Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 605
Ali Elkhateeb Avatar asked Dec 22 '19 17:12

Ali Elkhateeb


People also ask

Where are npm link stored?

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.

What does npm link do?

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.

How do I link npm modules?

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.

Does npm install create a dist folder?

npm install has nothing to do with creating (or failing to create) the dist folder, which is what OP is asking about.


1 Answers

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.

like image 53
velval Avatar answered Sep 29 '22 10:09

velval