Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Npm Install DevDependencies in separate directory

Tags:

node.js

npm

Is there a way for npm install to install the devDevpendencies in a separate directory enabling the ability to run build tasks while excluding the devDependencies in a dynamic/simple way?

like image 843
Ryan Leahy Avatar asked Nov 07 '14 21:11

Ryan Leahy


People also ask

Does npm install install devDependencies?

NPM installs devDependencies within the package. json file. The 'npm install' command should add all the dependencies and devDependencies automatically during installation. If you need to add specific devDependencies to your project, you can use this command- 'npm install --save-dev'.

How do you add devDependencies?

To add dependencies and devDependencies to a package. json file from the command line, you can install them in the root directory of your package using the --save-prod flag for dependencies (the default behavior of npm install ) or the --save-dev flag for devDependencies.

How npm install specific dependencies?

Summary. For npm install specific version, use npm install [package-name]@[version-number]. Use npm view [package-name] version to know the specific latest version of a package available on the npm registry. Use npm list [package-name] to know the specific latest version of an installed package.


1 Answers

I don't think that's possible, https://www.npmjs.org/doc/files/npm-folders.html states that the modules have to be in node_modules.

For your purposes you could copy everything but the node_modules folder and do npm install --production in the new copied folder, so you will only have production dependencies in the build.

This should accomplish what you want without much work:

rsync -av --progress yourproject yourbuilddir --exclude node_modules
cd yourbuilddir && npm install --production
like image 178
Lorenz Avatar answered Oct 21 '22 21:10

Lorenz