Reputation: 517
I am currently trying to package a javascript library. So far I have the package set up as follows:
npm build
puts everything in a build
directorymain
attribute in package.json
points to the entrypoint in build
that exports my libary's top-level API."{packagename}": "file:{pathToMyPackage}"
My question is this: I am now trying to troubleshoot my package from the other project. Each time I make changes, I must rebuild the project to reflect the changes AND I must rm -rf node_modules/{packagename} && npm install
on the project that is using the local package.
I know I can add some kind of watcher to the package that will build when new files are saved, but how can I make the higher-level project monitor changes to the local package it is using? Is there a magic tool for this sort of thing, or do people just add custom npm scripts while they are doing development on a dependency?
Thanks!
Upvotes: 1
Views: 1086
Reputation: 6994
What you're looking for is npm link
(https://docs.npmjs.com/cli/link).
package-a
depends on package-b
.
Navigate to package-b
's project folder on the command line. Run npm link
.
Now navigate to package-a
's folder and run npm link package-b
(You may need to run npm uninstall package-b
first; not sure).
This will create a symlink in package-a/node_modules/package-b
to package-b
's working directory. Any changes you make there will be reflected in the node_modules
for package-a
.
Just keep this in mind; if you break something while working on package-b
, package-a
may break too.
Upvotes: 2