Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm link, without linking devDependencies

It appears that when I run npm link, it will install the project globally, and it seems to install devDependencies with it.

Is there a way to run npm link without devDependencies, perhaps with the --only=production flag?

like image 549
Alexander Mills Avatar asked Jun 19 '17 23:06

Alexander Mills


3 Answers

In [email protected] or lower

When you run npm link in other_module then you will get both dependencies and devDependencies symlinked.

The --production flag doesn't change anything, still creates a symlink to the whole directory

In [email protected]

They fixed it!

If you remove node_modules and then do npm link --only=production, it runs an install before symlinking, and therefore devDependencies folder are indeed excluded.

like image 124
locropulenton Avatar answered Nov 04 '22 14:11

locropulenton


This is currently not possible with npm link. The problem is, if you install only prod dependencies in that dependency, you're able to link it, but you're not able to develop on that dependency anymore (since missing devDependencies). And vice-versa: If you install devDependencies, you can't link anymore.

The solution: A package called npm-local-development at https://github.com/marcj/npm-local-development

It basically does the same thing as npm link, but works around the devDependency limitation by setting up a file watcher and syncs file changes automatically in the background, excluding all devDependencies/peerDependencies.

  1. You install npm-local-development: npm i -g npm-local-development
  2. You create file called .links.json in your root package.
  3. You write every package name with its local relative folder path into it like so

    { "@shared/core": "../../my-library-repo/packages/core" }

  4. Open a console and run npm-local-development in that root package. Let it run in the background.

Disclaimer: I'm the author of this free open-source project.

like image 5
Marc J. Schmidt Avatar answered Nov 04 '22 14:11

Marc J. Schmidt


A workaround I use is npm pack then point to the packed file in the example

like image 1
Archimedes Trajano Avatar answered Nov 04 '22 12:11

Archimedes Trajano