简体   繁体   中英

Optionally use a local npm package in development environment

I am using an npm package that is shared across multiple services. We are in the early stages of development right now so there are a lot of changes. It's really annoying to have to publish changes to the package and then rebuild my project every time I make a change to this package. Is there a good way to just use the local package when NODE_ENV=development otherwise use the package in the npm repository? Thanks.

edit: also it would be great to be able to test my changes locally before publishing.

My solution was sort of hacky but it works for now. What I do is use lerna to create symlinks for my npm package. I have a non standard lerna.json file - ie I'm not using a /packages folder. After that, I use a script similar to the npm package absolutize-links. This converts the symlinks created with lerna to absolute paths. Then I set up some volumes with docker compose that point to my package. It's a bit of a complicated set up but I think it is working for now. I have nodemon running to ignore all of node_modules EXCEPT for my linked package. So when I make changes in my local filesystem to the package, the nodemon running in my container will restart. \\o/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM