Distinction ways npm i

npm i have the following ways:

npm i module_name              # 安装模块到项目目录下
npm i module_name -g            # -g 的意思是将模块安装到全局,具体安装到磁盘哪个位置,要看 npm config prefix的位置。 
npm i module_name -S(-save)      # --save 的意思是将模块安装到项目目录下,并在package文件的dependencies节点写入依赖。
npm i module_name -D(--save-dev)  # --save-dev 的意思是将模块安装到项目目录下,并在package文件的devDependencies节点写入依赖。


Specified as follows:

npm i module_name

  • Node_modules will moudule_name package to the directory
  • Does not modify package.json
  • When you run npm i command after, is not automatically installed moudule_name

npm i module_name -g

  • Install the module to a global, module packages are not saved in the project node_modules directory.
  • The module does not rely on written or dependencies devDependencies node.
  • Npm will not run when i download module initialization project.

npm i module_name -S

  • Node_modules will moudule_name package to the directory
  • Adds moudule_name in the dependencies of property package.json
  • When you run npm i command after installed automatically moudule_name to node_modules directory
  • After running npm i --production or variable value is specified NODE_ENV Production, automatically installed into msbuild node_modules directory, that is mounted on the package will run the online environment

npm i module_name –D

  • Node_modules will moudule_name package to the directory
  • Adds moudule_name in devDependencies property of package.json
  • When you run npm i command after installed automatically moudule_name to node_modules directory
  • After running npm i -production or variable value is specified NODE_ENV production, it is not automatically installed into node_modules directory moudule_name

Use principle:
module in devDependencies node that we need in the development, such as used in the project gulp, compress css, js modules. These modules in our project after deployment is not needed, so we can use the -D in the form of installation. Like emoudule_namepress These modules are necessary to run the project, should be installed in the dependencies node, so we should use to install the form -S.
Summed up in one sentence: the need to use run-time packages use -S, or use -D.

 

Transfer: https://www.jianshu.com/p/920c1a6e999c

Guess you like

Origin www.cnblogs.com/wzl96/p/11002029.html