What is the difference between the commonly used -S, -D, and -g when npm install installs the package?

一. npm i module_name -S

npm install is equivalent to npm i,
that is, npm install module_name --save writes dependencies,发布到生产环境。

这样安装是局部安装的, will be written into the dependency in the package.json file.

dependencies: 表示生产环境下的依赖管理;(没有这些依赖,生产环境下项目将无法运行)

To put it bluntly, if you install a library to build your project, such as echarts, element-ui, vue, etc. is actually working in the project, you can use -S to install.

二. npm i module_name -D

That is, npm install module_name --save-dev writes devDependencies,发布到开发环境。

这样安装是局部安装的, will be written into the devDependencies in the package.json file.

devDependencies : Indicates dependency management in the development environment; ( 不会影响生产环境下的项目运行)

If the library you installed is used for packaging and parsing code, such as webpack, babel, vite, etc., you can use -D
to install it. After the project is launched, these libraries are useless.

三. npm i module_name -g

Indicates global installation. After one installation, it can be used directly in other places.

4. npm delete module

  • 【npm uninstall/remove -S/-D xxx 】Delete the xxx module;
  • [npm uninstall/remove -g xxx] delete the global module xxx;

Guess you like

Origin blog.csdn.net/du_aitiantian/article/details/131377782