你如何防止安装“devDependencies"?Node.js (package.json) 的 NPM 模块? [英] How do you prevent install of "devDependencies" NPM modules for Node.js (package.json)?
问题描述
我的 package.json 文件中有这个(缩短版):
I have this in my package.json file (shortened version):
{
"name": "a-module",
"version": "0.0.1",
"dependencies": {
"coffee-script": ">= 1.1.3"
},
"devDependencies": {
"stylus": ">= 0.17.0"
}
}
我在 Mac 10.6.8 上使用 NPM 版本 1.1.1.
I am using NPM version 1.1.1 on Mac 10.6.8.
当我从项目根目录运行以下命令时,它会安装 dependencies
和 devDependencies
:
When I run the following command from the project root, it installs both the dependencies
and devDependencies
:
npm install
我的印象是这个命令安装了devDependencies
:
I was under the impression that this command installed the devDependencies
:
npm install --dev
我如何做到这样 npm install
只安装 dependencies
(所以生产环境只安装那些模块),而像 npm install --dev
安装 dependencies
和 devDependencies
?
How do I make it so npm install
only installs dependencies
(so production environment only gets those modules), while something like npm install --dev
installs both dependencies
and devDependencies
?
推荐答案
npm install
命令将安装 devDependencies
和其他 dependencies
在包目录中运行,在开发环境中(默认).
The npm install
command will install the devDependencies
along other dependencies
when run inside a package directory, in a development environment (the default).
使用npm install --only=prod
(或--only=production
)安装only dependencies
,而不是 devDependencies,
无论 NODE_ENV
环境变量的值如何.
Use npm install --only=prod
(or --only=production
) to install only dependencies
, and not devDependencies,
regardless of the value of the NODE_ENV
environment variable.
来源:npm 文档
注意:您可能还需要--no-optional
注意:在npm (2015-08-13) v3.3.0之前,该选项被称为--production
,即npm install --production
.
Note: Before v3.3.0 of npm (2015-08-13), the option was called --production
, i.e. npm install --production
.
这篇关于你如何防止安装“devDependencies"?Node.js (package.json) 的 NPM 模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!