node.jsreactjsnpmnpm-link

npm link only dist folder


Is there a way to restrict npm link to create the symlink only to point at ./dist?

I am struggling so far as I want to test my library (react component) locally before publishing.

In my package.json I have included the main (entry point):

"main": "./dist/index.js"

But still when I run npm link it links to the parent folder which has node_modules and so on. This is causing problems cause now I have 2 react apps installed.

I thought of a way to exclude node_modules but I couldn't even find a way to do that.


Solution

  • This is actually simpler than expected. First run ng build to build your library project, then go under the dist folder and run npm link from there instead of the library root project. The symlink will be created pointing to the dist folder instead.