乐闻世界logo
搜索文章和话题

What is the difference between --save and -- save - dev ?

1个答案

1

In the Node.js package manager npm, the --save and --save-dev options are used to install new dependencies and record them in the project's package.json file. However, they record different types of dependencies for distinct purposes.

--save

Dependencies installed with --save are added to the dependencies section of the package.json file. These dependencies are required for the project to run in production. Specifically, they are essential for the project to operate normally in a production environment.

For example, if I'm developing a website using the Express framework, Express is a runtime dependency and should be installed with --save:

bash
npm install express --save

--save-dev

Dependencies installed with --save-dev are added to the devDependencies section of the package.json file. These dependencies are needed during development but are not required in a production environment. Typically, this includes testing frameworks, build tools, and code formatting utilities.

For example, if I'm using Webpack to bundle my JavaScript files, since Webpack is only used for bundling during development and not directly used in production, it should be installed with --save-dev:

bash
npm install webpack --save-dev

Summary

In summary, --save is used to install dependencies required for the project to run in production, while --save-dev is used to install dependencies only needed during development. Properly distinguishing between these two types of dependencies helps maintain the project's dependency list, ensuring a streamlined and efficient production environment.

2024年6月29日 12:07 回复

你的答案