npm install --save/--save-dev的区别

官方文档只是简单的说:

--save: Package will appear in your dependencies. 

--save-dev: Package will appear in your devDependencies.

真正的区别是:

--save-dev:

dev指的是development:This is useful when installing development-only packages, like grunt, gulp or your testing library. Thus, when you are distributing your code to production, these dependencies will not be available.

这就是说,devDependencies下列出的模块,是我们开发时用的,比如grunt-contrib-uglify, 我们用它来混淆js文件,它们不会被部署到生成环境。有一个方法可以很好的检验这一点,将node_modules删掉,然后npm install --production会发现,只会安装到dependencies。

以及其他方便我们开发的工具,比如angular, vue, sass等都只需要安装到devDependencies。

--save:

You will use this option when you want to save a package dependency for distribution. Item such as angularjs, or any other module that is required at run time by your program.

dependencies下的模块,是我们生产环境中需要的依赖。

 

参考链接http://imcodebased.com/npm-save-or-save-dev-which-one-to-use/

posted @ 2016-11-23 10:17  kakaguo  阅读(2237)  评论(0编辑  收藏  举报