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.
When you run npm link in a module's root directory, npm creates a symbolic link from your “global node_modules” directory to the local module's directory. The “global node_modules” directory is a special directory where all modules installed with npm install -g are stored.
npm link is an npm command which, when used correctly, creates a link between projects to facilitate development in a local environment. This allows you to reference my-package locally (instead of the npm-hosted package) without modifying package. json in my-project.
Example: Let the local-dir is the local directory and project-dir is the project directory and local_module is the local module package you want to install, first go to the local-dir and type npm link and next go to the project directory and type npm link <local_module> this will link your local module to your project.
npm install has nothing to do with creating (or failing to create) the dist folder, which is what OP is asking about.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With