npm install -dev与npm install --save-dev区别

原文作者:_FEE 
来源:CSDN 
原文地址:https://blog.csdn.net/Randy_Shenyp/article/details/73740920 


当你为你的模块安装一个依赖模块时,正常情况下你得先安装他们(在模块根目录下npm install module-name),

然后连同版本号手动将他们添加到模块配置文件package.json中的依赖里(dependencies)

-save和save-dev可以省掉你手动修改package.json文件的步骤。 
npm install module-name -save 自动把模块和版本号添加到dependencies部分(生产环境) 
例如:

"dependencies": {

       "gulp-install": "^0.6.0"

npm install module-name -save-dve 自动把模块和版本号添加到devDependencies部分(开发环境) 
例如:

"devDependencies": {
    "del": "^2.2.2",
    "gulp": "^3.9.1",
    "gulp-autoprefixer": "^3.1.0",
    "gulp-cached": "^1.1.0",
    "gulp-changed": "^1.3.0",
    "gulp-clean": "^0.3.2",
    "gulp-concat": "^2.6.1",
    "gulp-cssnano": "^2.1.2",
    "gulp-if": "^2.0.1",
    "gulp-imagemin": "^3.1.1",
    "gulp-install": "^0.6.0",
    "gulp-jshint": "^2.0.4",
    "gulp-livereload": "^3.8.1",
    "gulp-load-plugins": "^1.5.0",
    "gulp-notify": "^2.2.0",
    "gulp-plumber": "^1.1.0",
    "gulp-rename": "^1.2.2",
    "gulp-sass": "^3.1.0",
    "gulp-sass-inheritance": "^0.5.1",
    "gulp-sourcemaps": "^1.6.0",
    "gulp-uglify": "^2.0.1",
    "inheritance": "^0.2.1",
    "jshint": "^2.9.4",
    "path": "^0.12.7"
  },

通过这些命令,我们会得到一个新的package.json。

假如:删除node_modules目录,然后执行 npm install --production,可以看到,npm只帮我们自动安装package.json中dependencies部分的模块;如果执行npm install ,则package.json中指定的dependencies和devDependencies都会被自动安装进来。

猜你喜欢

转载自blog.csdn.net/dyr_1203/article/details/84958176