The difference between --save and --save-dev in npm install

        The superficial difference is that --save will add the dependent package name to the package.json file under the dependencies key, and --save-dev will add it to the package.json file under the devDependencies key,

        The real difference between them is that npm's own documentation says that dependencies are runtime dependencies, and devDependencies are development-time dependencies, that is, the modules listed under devDependencies are used during development, such as when we install the js compressed package gulp-uglify, We use the "npm install --save-dev gulp-uglify" command to install, because we don't use it after release, but only during our development. The modules under dependencies are the modules that we need to depend on after publishing, such as the jQuery library or the Angular framework. We must depend on them after development, otherwise it will not work.

        When using npm install normally, the modules in dependencies and devDependencies will be downloaded. When using npm install –production or specifying the value of the NODE_ENV variable as production, only the modules in dependencies will be downloaded.

Overall feature comparison  

npm install module:

  • will install the module package into the node_modules directory
  • will not modify package.json
  • When running the npm install command afterwards, the module package will not be automatically installed

npm install module --save

  • Will install the module package to the node_modules directory summary
  • Will modify package.json to add the module name and version number to the dependencies section
  • When you run the npm install command later, the module package will be automatically installed
  • After running npm install --production or indicating that the NODE_ENV variable value is production, the module will be automatically installed in the node_modules directory, that is, the package will be installed when the online environment is running

npm install module --save-dev

  • Will install the module package to the node_modules directory summary
  • will modify package.json to add the module name and version number to the devDependencies section
  • When you run the npm install command later, the module package will be automatically installed
  • After running npm install --production or indicating that the NODE_ENV variable value is production, msbuild will not be automatically installed in the node_modules directory, that is, the online environment will not be installed.

First, --save and --save-dev save us the step of manually modifying the package.json file. Some of the packaging tools we use and those that are not required by the project are placed in devDependencies.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325938943&siteId=291194637