node.js 如何使用 npm 仅安装“devDependencies”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36999461/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install only "devDependencies" using npm
提问by Nesan Rajendran
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.
我正在尝试仅安装 package.json 文件中列出的“devDependencies”。但是以下命令都没有按我的预期工作。以下所有命令也安装了我不想要的生产依赖项。
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. :(
我想不出更多的方法来告诉 npm 单独安装 devDependencies。:(
回答by Ahmed farag mostafa
Check the NPM docs for install:
检查NPM 文档以进行安装:
With the
--productionflag (or when theNODE_ENVenvironment variable is set to production), npm will not install modules listed indevDependencies.The
--only={prod[uction]|dev[elopment]}argument will cause either only devDependencies or only non-devDependencies to be installed regardless of the NODE_ENV.
使用
--production标志(或当NODE_ENV环境变量设置为生产时),npm 将不会安装devDependencies.该
--only={prod[uction]|dev[elopment]}参数将导致仅安装 devDependencies 或仅安装非 devDependencies,而不管 NODE_ENV。
Have you tried the following?
您是否尝试过以下方法?
npm install --only=dev
回答by Jeff
npm install thePackageName --save-dev
This works fine for me.
这对我来说很好用。
回答by Roger Muscito
npm i -D
npm i -D
An optional short version.
可选的简短版本。
回答by Piyush Sonigra
Running npm install, It will install all dependencies under devDependencies` or dependencies.
运行npm install,它将安装devDependencies`或dependencies下的所有依赖项。
For installing and save packages as dev dependencies in package.json,
npm install package_name --save-devor pass option -D
用于在 package.jsonnpm install package_name --save-dev或 pass 选项中安装和保存包作为开发依赖
项-D
For installing all packages under devDependencies,
npm install --only=dev
要安装devDependencies下的所有软件包,
npm install --only=dev
For installing and save packages as prod or only dependencies in package.json,
npm install package_name --save-prodor pass option -Por npm install package_name
用于在 package.json 中安装和保存包为 prod 或仅依赖项,
npm install package_name --save-prod或传递选项-P或npm install package_name
For installing all packages under dependenciesor Prod dependencies,
set Environment variable NODE_ENV=productionor pass it with the command NODE_ENV=production npm installor npm install --only=prod
要安装依赖项或Prod 依赖项下的所有包,请设置环境变量NODE_ENV=production或使用命令 NODE_ENV=production npm install或npm install --only=prod
Instead of using installin npm command like npm installyou can just use ilike npm i, short of install.
不像install在 npm 命令中使用,npm install你可以只使用ilike npm i,而不是安装。

