background
As a front-end development, if there are multiple NPM packages in NPM package management, each NPM package will have a separate Git repository, which will be very cumbersome to manage and too many Git repositories, and version management will be chaotic. At this time, it is particularly important to use Monorepo multi-package architecture to manage NPM common packages. Lerna is a multi-package management tool.
For example, Babel, a syntax-conversion tool commonly used in the front end, is used for multi-packet management with Lerna.
Version management of LERna
fix mode
The default version management mode of Lerna is fix mode, and the versions of all subpackages are uniform. Using Lerna init, you can create a Monorepo project, update the version through Lerna Version, and publish the corresponding updated NPM package through Lerna publish.
independent mode
If you do not want the versions of the subpackages to be uniform, you can create projects using lerna Init –independent, where each subpackage is updated and a separate subpackage is updated.
Lerna common commands
lerna init
To initialize lerNA projects, NPM install lerna -g to install lerNA globally, and then initialize a LerNA project via lerna init
Here’s an example:
// Create a folder
mkdir my-monorepo && cd my-monorepo
// Initialize the lerna project
lerna init
// a new lerna project is initialized with the Packages directory in which subpackages can be created
lerna create xxx
Copy the code
lerna create
If you want to create a js-SDK subpackage under the newly initialized lerna project, you can create it by using the lerna create js-sdk command.
lerna add
For example, lerna add module-1 packages/ js-SDK can add dependencies to the jS-SDK subpackages
lerna boostrap
Install node_modules dependencies for all subpackages
lerna clean
Remove node_modules dependencies for all subpackages
lerna version
Update all subpackage versions of Lerna and push git remote
lerna publish
Lerna subpackage updated before publication, published to NPMJS
conclusion
Because lerna is used to manage multiple packages recently, today I briefly recorded the basic usage of LERNA. It is really convenient to use LerNA to manage NPM packages. It is strongly recommended that all r&d teams use LerNA to manage NPM common libraries. I’ll write down some notes and interesting uses of LerNA later.
Today opened the nuggets column, later as far as possible to learn more summary.