简体   繁体   中英

NPM Link to Src Dir Instead of Lib Dir

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?

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.

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