How to install only “devDependencies” using npm

2019-03-09 15:40发布

问题:

I am trying to install ONLY the "devDependencies" listed in my package.json file. But none of the following commands work as I expect. All of the following commands install the production dependencies also which I do not want.

npm install --dev
npm install --only=dev
npm install --only-dev

I cannot think of any more ways of telling the npm to install the devDependencies alone. :(

回答1:

Check the NPM docs for install

"With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies."

"The --only={prod[uction]|dev[elopment]} argument will cause either only devDependencies or only non-devDependencies to be installed regardless of the NODE_ENV."

Have you tried

npm install --only=dev


回答2:

npm install --save-dev

This works fine for me.