开发依赖关系与node.js中的依赖关系

在一个节点项目中,我发现了两种依赖关系:

"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模块仍然在那里。

本文给出了两者之间差异的很好的解释:

https://www.linkedin.com/pulse/npm-dependencies-vs-devdependencies-daniel-tonon

文章片段:

 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”标志将模块保存为依赖项。 如果这是你的模块不需要的function,但需要进行testing,那么使用“–save-dev”标志。

 # For dependent modulesnpm 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 

两者的主要区别是:

在开发中,开发人员根据需要定制或修改节点包。 例如,在做出grunt任务时,我们根据Gruntfile中的要求更改任务,与您正在使用的babel的情况相同。

在依赖关系中,开发人员直接使用节点包而不用更改ex-express。

希望它清除你的怀疑。