-
package.json
-
--save 等价于 -S,项目上线以后也需要用到的
-
--save-dev 等价于 -D ,只在开发阶段使用
以上两种方式都会在npm install 执行时把信息写入package.json中,--save会把依赖名称及版本号写入dependencies的属性下,--save-dev会写入devDependencies下
-
dependencies和
devDependencies:
dependencies
是运行时依赖,devDependencies
是开发时的依赖。
dependencies
下的模块,则是发布后还需要使用的依赖模块,譬如jQuery
库或者Vue
框架等,在开发完后肯定还要依赖它们,否则就运行不了。
devDependencies
下列出的模块,是开发时使用,比如安装js
的压缩包gulp-uglify
时,采用的是npm install --save-dev gulp-uglify
命令安装,因为在发布后用不到它,而只是在开发才用到它。正常使用
npm install
时,会下载dependencies
和devDependencies
中的模块,当使用npm install --production
或者注明NODE_ENV
变量值为production
时,只会下载dependencies
中的模块。