CFXIXI工作室首页
CF西西的博客 | Package.json中dependencies与devDependencies的区别

Package.json中dependencies与devDependencies的区别

21. 六月 2016

转自:https://www.zfanw.com/blog/difference-between-dependencies-and-devdependencies.html

npm install在安装node模块时,有两种命令参数可以把它们的信息写入package.json文件:

  1. –save
  2. –save-dev

但它的文档里1,只提到一个小区别,--save会把依赖包名称添加到package.json文件dependencies键下,--save-dev则添加到package.json文件devDependencies键下,譬如:

{
  "name": "yo",
  "version": "0.0.0",
  "dependencies": {},
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-copy": "~0.4.1",
    "grunt-contrib-concat": "~0.3.0",
    "grunt-contrib-uglify": "~0.2.0",
    "grunt-contrib-compass": "~0.7.0",
    "grunt-contrib-jshint": "~0.7.0",
    "grunt-contrib-cssmin": "~0.7.0",
  }
}

不过这只是它们的表面区别。它们真正的区别是,devDependencies下列出的模块,是我们开发时用的,比如grunt-contrib-uglify,我们用它混淆js文件,它们不会被部署到生产环境。dependencies下的模块,则是我们生产环境中需要的依赖。

nodeJS