Skip to content

molychn/tetrisrepo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

建库说明

tetrisrepo主要想实现多包管理前端组件库,所以在此需求上尝试使用lerna实现

npx lerna init --independent

直接在该目录内运行上述命令会生成相应的lerna配置与目录结构,其初始化结构中较为关键的packages/lerna.json

lerna create [name]

使用create命令快速生成packages/name目录及其内相应文件与配置。

lerna add

添加公共依赖,加上--scope=pkgName用于单独依赖添加。

lerna bootstrap

重新安装所有依赖。

lerna link

通过在其他包中添加依赖本地开发的包,使用lerna link命令来进行关联

lerna hoisting

使用yarn/workspaces实现lerna hoisting,可以在根目录管理依赖。

// lerna.json
{
  "npmClient": "yarn",
  "useWorkspaces": true
}

依赖托管后,lerna的packages将会被顶级package.json的workspaces覆盖

// package.json
{
  // ...
  "workspaces": [
    "packages/*"
  ]
}

lerna publish config

在lerna.json中配置publish,明确注册表配置,同时配置ignoreChanges避免不必要的版本升级。

{
  "version": "1.1.3",
  "npmClient": "npm",
  "command": {
    "publish": {
      "ignoreChanges": ["ignored-file", "*.md"],
      "message": "chore(release): publish",
      "registry": "https://npm.pkg.github.com"
    },
    "bootstrap": {
      "ignore": "component-*",
      "npmClientArgs": ["--no-package-lock"]
    }
  },
  "packages": ["packages/*"]
}
  • version: the current version of the repository.
  • npmClient: an option to specify a specific client to run commands with (this can also be specified on a per command basis). Change to "yarn" to run all commands with yarn. Defaults to "npm".
  • command.publish.ignoreChanges: an array of globs that won't be included in lerna changed/publish. Use this to prevent publishing a new version unnecessarily for changes, such as fixing a README.md typo.
  • command.publish.message: a custom commit message when performing version updates for publication. See @lerna/version for more details.
  • command.publish.registry: use it to set a custom registry url to publish to instead of npmjs.org, you must already be authenticated if required.
  • command.bootstrap.ignore: an array of globs that won't be bootstrapped when running the lerna bootstrap command.
  • command.bootstrap.npmClientArgs: array of strings that will be passed as arguments directly to npm install during the lerna bootstrap command.
  • command.bootstrap.scope: an array of globs that restricts which packages will be bootstrapped when running the lerna bootstrap command.
  • packages: Array of globs to use as package locations.

除此之外,如果你的包名是带 scope 的,需要在那个包的 package.json 中设置 publishConfig.access 为 "public"。

某篇文章里提到包名写到scope的问题,这里还不是很理解,后期有用到再看看。

About

No description, website, or topics provided.

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.md

Stars

Watchers

Forks

Packages

No packages published