当前位置:网站首页>How to use lerna to manage multiple packages
How to use lerna to manage multiple packages
2022-06-21 07:34:00 【u012804784】
High quality resource sharing
| Learning route guidance ( Click unlock ) | Knowledge orientation | Crowd positioning |
|---|---|---|
| 🧡 Python Actual wechat ordering applet 🧡 | Progressive class | This course is python flask+ Perfect combination of wechat applet , From the deployment of Tencent to the launch of the project , Create a full stack ordering system . |
| Python Quantitative trading practice | beginner | Take you hand in hand to create an easy to expand 、 More secure 、 More efficient quantitative trading system |
Why use lerna
Divide the large code warehouse into several independent versions software package (package) Very useful for code sharing . however , If something changes Across multiple code repositories, it's going to be very trouble And it's hard to track , also , Testing across multiple code repositories will quickly become very complex .
To solve these ( And many others ) problem , Some projects will The code warehouse is divided into multiple packages (package), And store each software package in a separate code warehouse . however , for example Babel、 React、Angular、Ember、Meteor、Jest And a lot of other projects are in A code repository contains multiple packages (package) And develop .
Lerna It's a tool , in the light of Use git and npm Optimize the workflow of managing multi package code warehouse
npm initialization
New folder spring-breeze, Input at integrated terminal
npm init -y
The root directory will generate package.json:
{
"name": "spring-breeze",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
install lerna
Global installation lerna
perform :npm i lerna -g
After installation :lerna init
After the execution, such a directory structure appears
- packages( Catalog )
- lerna.json( The configuration file )
- package.json( Project description file )
Initialize two package
By default ,package It's on the packages In the catalog . To create a package, you can use the command lerna create [loc]
lerna create core packages/core
lerna create core packages/tools
take packages/core/lib/core.js Change it to :
'use strict';
console.log(" I am a core package ~~")
take packages/tools/lib/tools.js Change it to :
'use strict';
console.log(" I am a tools package ~~")
At this point, the directory structure is
-- packages( Catalog )
-- core
...
-- lib
-- core.js
-- package.json
-- README.md
- tools
...
-- lib
-- tools.js
-- package.json
-- README.md
- lerna.json( The configuration file )
- package.json( Project description file )
...
Modify package name
In order to prevent duplicate names , The package name is generally changed to @ organization / package , Such as the current project core Should be changed to :@spring-breeze/core;tools Change it to :@spring-breeze/tools
for example core modular :
- packages/core/package.json:
{
"name": "@spring-breeze/core",
"version": "0.0.1",
"description": "> TODO: description",
"author": "******",
"homepage": "",
"license": "ISC",
"main": "lib/core.js",
"directories": {
"lib": "lib",
"test": "\_\_tests\_\_"
},
"files": [
"lib"
],
"repository": {
"type": "git",
"url": "******"
},
"scripts": {
"test": "echo \"Error: run tests from root\" && exit 1"
}
}
Install third party package lerna add
- Add public dependencies
Execute at root ( It is the same in which directory ):lerna add lodash
You will find core and tools All installed lodash
- Add a separate dependency
lerna add jquery --scope=core
core Will be installed jquery
Delete dependency lerna clean
perform lerna clean All packages will be deleted node_modules
Install all dependencies lerna bootstrap
perform lerna bootstrap All dependencies will be reinstalled
Test local package
If the two packages developed locally are related , use lerna Debugging is very simple , You only need to write the required local package version number to the dependent execution :lerna link That's all right. ; For example, in core Module USES tools modular
- package Add dependency :“@spring-breeze/tools”: “^0.0.1”
{
"name": "@spring-breeze/core",
"version": "0.0.1",
"description": "> TODO: description",
"author": "******",
"homepage": "",
"license": "ISC",
"main": "lib/core.js",
"directories": {
"lib": "lib",
"test": "\_\_tests\_\_"
},
"files": [
"lib"
],
"repository": {
"type": "git",
"url": "******"
},
"dependencies": {
"@spring-breeze/tools": "^0.0.1"
},
"scripts": {
"test": "echo \"Error: run tests from root\" && exit 1"
}
}
After the addition is completed, execute lerna link
- core Use in :packages/core/lib/core.js
'use strict';
require("@spring-breeze/tools")
node perform core.js You will find that the console prints : I am a tools package ~~. In this way, you can perform local debugging
Prepare for release
After debugging, it can be released , The release process is as follows :
- register npm Account
- New organization spring-breeze( It depends on your project )
- perform npm login
- Respectively in core and utils Under the package.json Middle configuration
"publishConfig": {
"access": "public"
}
- newly build gitignore
*node\_modules
- newly build git Warehouse , Put the project git remote add “ Yours git Warehouse ”, And submit the project to git Warehouse
git remote add https://gitee.com/geeksdidi/spring-breeze.git
git add .
git commit -m " initialization "
git push -u origin master
- newly build LICENSE.md( It can be an empty file )
- Modify a file to execute lerna publish
Be careful : Each time a new version is released, the code is submitted to git On
View published package
land npm Official website You can see your own package
边栏推荐
- app安全渗透测试详细方法流程
- stm32中定义和声明问题
- ANSA二次开发 - 外部程序采用socket与ANSA实现通信
- Arduino about software uninstallation and library uninstallation
- mysql分页查询如何优化
- Black technology, real-time voice simulation
- . Net 4.5 asynchronous programming pilot (async and await)
- Four necessary steps for building a digital factory
- The concept of tree
- Realize the industry vision of decentralization, safety, accuracy and real-time price feeding
猜你喜欢

mysql中执行存储过程的语句怎么写

海思系列量产硬件调试记录

RPA (shadow knife) does not need to write code to capture the product information of an East

WordPress website security in 2022

Using XAML only to realize the effect of ground glass background panel

传输层 TCP首部-序号和确认号

Course design of supply chain modeling and simulation based on Flexsim

Google Earth engine (GEE) - US native lithology data set

17 statistics and their sampling distribution statistics and distribution

mysql不是内部命令如何解决
随机推荐
Best practice | how to use Tencent cloud micro build to develop enterprise portal applications from 0 to 1
arduino有关软件卸载,库的卸载问题
A shell script to realize automatic expiration of Prometheus push gateway indicators
PostgreSQL数据库头胎——后台一等公民进程StartupDataBase StartupXLOG函数进入Recovery模式
stm32中定义和声明问题
Record context information through ThreadLocal (record user information to realize global operation)
EasyExcel-排除展示字段-02
mysql的安装路径如何查看
The concept of tree
Horizontal slot, one line of code can directly convert the web page to PDF and save it (pdfkit)
2022年的WordPress网站安全问题
Asp. Net web API 2 Lesson 1 - getting started
How MySQL closes a transaction
Pinia advanced: elegant setup (functional) writing + encapsulation into your enterprise project
Unittest use
mysql存储过程中的循环语句怎么写
How to start wireless network service after win10 system installation
为什么智慧城市需要数字孪生?
A table to easily understand the prefix and suffix of increment and decrement operators
JS operation cookie, JS setting cookie value, JS reading cookie value