Lerna is used to manage projects with multiple packages that may refer to each other.
Lerna manages the version numbers of subprojects in two ways
- Fixed/Locked mode (default) : This mode is executed every time
lerna publish
Will upgrade the packages involved to the latest version, and the developer just needs to make sure to release the next oneversion
. - Independent mode: managed by the developer
version
, each timelerna publish
You need to determine the next version number for each package.
The basic use
The following command is based on YARN.
Install the installation
yarn global add lerna
Init Initializes the project
After the lerna init command is executed, the corresponding directory structure is generated.
lerna-repo/
package.json
lerna.json
packages/
package-1/
package.json
package-2/
package.json
Copy the code
Lerna. Json configuration
{
"version": 1.1.3 "".// Project version
"npmClient": "npm".// The default value is NPM. You can change it to yarn
"command": { // Lerna built-in command configuration
"publish": {
"ignoreChanges": ["*.md"."**/test/**",].// Ignore changes to some files when publishing. This configuration can reduce unnecessary Publish.
"message": "chore(release): publish" // git commit message}},"packages": ["packages/*"]}Copy the code
Create creates a subproject
Lerna create
creates a subproject and generates the corresponding package.json as prompted by the interaction
Add Adds dependencies
lerna add <package>[@version] [--dev] [--exact]
lerna add eslint
: All bags will be loadedeslint
.lerna add eslint --scope=package1
: onlypackage1
Will be installed.lerna add eslint packages/prefix-*
: in accordance withprefix
The bag will be loaded.
options:
-dev
Added:devDependencies
--exact
: Installs only a specific version
If the subproject is added, it will be soft-linked to the corresponding project via link. lerna add package1 –scope=package2
Run Run the NPM script command
lerna run <script> -- [..args]
lerna run test
: will execute all subprojectstest
.lerna run --scope package1 test
: only performpackage1
In thetest
.lerna run --ignore package-* test
: Only matches are executedpackage-*
Outside of the projecttest
Exec Executes any command
lerna exec -- <command> [..args]
Similar to lerna run, except it can execute any command. eg: lerna exec — rm -rf ./node_modules
Other commands
lerna bootstrap
: Installs dependencies of sub-projects, soft links projects that reference each other, and executes them in sub-projectsnpm run prepublish
andnpm run prepare
--hoist [glob]
: will match dependencies of subitems (eg:eslint
.jest
Etc.), unified in the root directorynode_modules
To reduce installation time, but onlynpmClient=npm
- nohoist [glob]
: Match dependencies (eg:babel
) is installed in a subprojectnode_modules
In the
lerna clean
: to delete a subitemnode_modules
lerna link
With:bootstrap
The second step.
Use the advanced
Lerna-changelog
Lerna-changelog generates Changelog for a project based on PR
Refer to repo
Using the step
- from
master
Branch outfeature
/bugfix
Equal branches, referencegit-flow. - After completion of development
commit
, recommended to usecommitizenTo regulatecommit msg
, while helping to generate subsequent subprojectschangelog
. - The new branch
push
toremote
End. - create
pr
And play onlabel
Be sure to type it herelabel
.learn-changelog
Is based onlabel
To determine thepr
Belong tofeature
/bugfix
/document
And so on. - Remember to in
merge
Before play onlabel
. - for
merge pr
Operation. - Local switch to
master
Branch and proceedpull
Operation. - perform
lerna-changelog
, can get a sharechangeling
.
Pay attention to
The label of pr cannot be set arbitrarily, it must be declared in the project to take effect.
Official default support product/enhancement/bug/documentation/internal, need in the package. If you want to use other json accordingly in the configuration.
{
"changelog": {
"labels": {
"feat": ":rocket: New Feature"."bug": ":bug: Bug Fix"."doc": ":memo: Documentation"."internal": ":house: Internal"."breaking": ":boom: Breaking Change"}}}Copy the code
Subproject changelog
This has not yet been done, so refer to README for details
conclusion
The use of LERNA has been introduced, the above content can meet the daily development needs, more details need to refer to the official documents.