This is the 18th day of my participation in Gwen Challenge
Front-end scaffolding development (IV), Lerna
Lerna is an optimized multi-package project management tool based on Git + NPM
1. Problems solved by Lerna
-
Repetitive operations on complex projects, such as local link for multiple packages, unit testing for multiple packages, and code distribution for multiple packages, can be understood better if you have read and practiced the article front-end scaffolding development, Practice makes Sense
-
Version consistency issues for complex projects
- Version consistency at release time
- Interdependent versions are upgraded after release
2. Lerna develops scaffolding processes
Look at this picture and try it out! Create a lerna-test-cli
2.1 Hands-on practice
- Create a project file, such as lerna-test-cli
npm init
Initialize your project cnpm i lerna -D
Install lerNA dependenciesnpx lerna -v
Check the version number to see if the installation is successful, and then usenpx lerna init
Go initialize your project, and one will appearlerna.json
The file
{
"packages": [
"packages/*"]."version": "1.0.0"
}
Copy the code
We are going to use these packages to manage all the other sub-packages in the project
NPX lerna create your package
, create a package
There is a special point to note here: our packages will be published on the NPM, so before creating the package to check whether the name is registered, it is best to create an organization and put the package, to avoid conflicts with other users registered
Lerna core operation
Other common operations can be NPX lerna-h to see the help manual, the focus of the following
3.1 lerna add
- For all the
package
Install the associated dependencies,npx lerna add <package>[@version] [--dev] [--exact] [--peer]
- Install dependencies for a particular package,
NPX lerna add <package> < specific package path name >
.
3.2 lerna link
The project package builds soft links, similar to NPM Link, but important to note that it soft links packages with cross-reference packages
3.3 lerna exec
Run arbitrary commands in each package
3.4 lerna run
Run an instruction for a package
4. Lerna release process
4.1 runlerna version
This command identifies the changed package –> create a new version number –> modify package.json –> commit the change to tag the version –> push it to Git. The version number follows Semver, for which please click this link
4.2 lerna changed
List the packages that lerna publishes to update next release.
. XXX -one XXX -two lerna success found 2 packages ready to publish #Copy the code
4.3 lerna publish
Features: can play tag, upload Git, upload NPM.
If your package name has scope for example: “name”: “@xxxx/ XXX “, that needs to be added in packes.json
"publishConfig": {
"access": "public"
}
Copy the code
What is scope package?
Scope means scope or scope, and also value namespace. So a package with scope represents a package namespace. Assume that the name attribute in package.json is as follows:
{
"name":"@username/project-name"
}
Copy the code
Username is the name of the login account.