Life is too short to waste a second

npm link to dev faster

sometime we may neednt to install all package by lerna. But we will found when we build wallex-base, wallex-web wont work. Thats beacuse lerna link local wallex-base to wallex-web. but we install by npm is actually wallex-base in remote.

you can use npm link to create link

wallex-base:

npm link

/Users/wenjiejin/.nvm/versions/node/v12.18.3/lib/node_modules/@wallex/base -> /Users/wenjiejin/wallex-dev/packages/wallex-base

you will see in the nvm @wallex/base is already link to local files.

then lets go to wallex-web and run: npm link @wallex/base.

/Users/wenjiejin/wallex-dev/packages/wallex-web/node_modules/@wallex/base -> /Users/wenjiejin/.nvm/versions/node/v12.18.3/lib/node_modules/@wallex/base -> /Users/wenjiejin/wallex-dev/packages/wallex-base

now wallex-web will use local wallex-base codes to run

since its global link (in nvm)

you may need to unlink it when more wallex-base need to link

wallex-base:

npm unlink

wallex-web:

npm unlink @wallex/base

However, lerna link scope is not global (actually it dosent use npm link). Its just for one project. We can find out how lerna do it so elegent by reading its core code

https://github.com/lerna/lerna/blob/72414ec1c679cf8a7ae4bfcefce52d50a6120a70/utils/create-symlink/create-symlink.js

which use fs.symlink to do it.

we can also write a simple script to do it!

发表评论

电子邮件地址不会被公开。