Max Paymar
Max Paymar

Reputation: 718

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.

Upvotes: 1

Views: 143

Answers (1)

Max Paymar
Max Paymar

Reputation: 718

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 - i.e. 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/

Upvotes: 2

Related Questions