Reputation: 43351
I'm working on several NPM modules at a time - there is one main module that imports three others. I have used npm link
to link the others to the main module, however I am writing all the modules using Babel to transpile the source. When I build one of the modules I run npm run build
which runs the transpilation and compiles the files in the modules src
directory to its lib
directory. However, because each of the modules' package.json file specifies the main file location as lib/index.js
this means that for a linked module to appear updated to my main module, I always need to build it.
Is there any way (when using npm link
) to have it link to the src
dir instead of the lib
dir? Failing that, is there a better way to achieve what I want - to see updates to the linked modules code reflected instantly in the main module?
Upvotes: 4
Views: 3140
Reputation: 172
1) An easy way to resolve this is to temporarily change the entry point in your library module's package.json
when developing:
/* library-module/package.json */
{
"main": "src/index.js",
...
}
Now wherever you npm link library-module
, you should be loading the library module's src/index.js
2) Alternatively, you can setup a watch task to always build to lib
after detecting changes in src
. This way, your new changes will always be reflected in your consuming module.
Upvotes: 4