在一个 Node 项目中,我发现了 2 种依赖项:
"dependencies": {
"axios": "0.9.1",
"express": "4.13.4",
"lodash": "4.6.1",
"react": "^0.14.7",
"react-dom": "^0.14.7",
"react-redux": "^4.4.0",
"react-router": "^2.0.0",
"redux": "^3.3.1"
},
"devDependencies": {
"babel-core": "^6.5.2"
}
我知道作者是通过 npm install babel-core --save -dev
但那是为了什么?当你推送代码时,devDependencies
模块仍然存在。
最佳答案
我写了一篇关于这个的文章,但是它被删除了。
文章摘录:
mod-a
dev-dependents:
- mod-b
dependents:
- mod-c
mod-d
dev-dependents:
- mod-e
dependents:
- mod-a
----
npm install mod-d
installed modules:
- mod-d
- mod-a
- mod-c
----
checkout the mod-d code repository
npm install
installed modules:
- mod-a
- mod-c
- mod-e
发布到 npm
如果您要发布到 npm,那么为正确的模块使用正确的标志很重要。如果它是你的 npm 模块需要运行的东西,那么使用“--save”标志将模块保存为依赖项。如果它是您的模块不需要运行但需要进行测试的东西,则使用“--save-dev”标志。
# For dependent modules
npm install dependent-module --save
# For dev-dependent modules
npm install development-module --save-dev
不适用于 npm
如果您不发布到 npm,从技术上讲,您使用哪个标志并不重要。但是,我发现对将非标准代码引入源文件的模块使用“--save”标志是一个好习惯。然后对编译器运行所需的模块使用“--sav-dev”标志。
# For modules that introduce non-standard source code
npm install source-module --save
# For modules that your compiler needs to function
npm install compiler-module --save-dev
关于node.js - 开发依赖与 node.js 中的依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39716447/