简体   繁体   English

是不是npm install -save-dev gulp-uglify与npm install gulp-uglify不同

[英]Is npm install --save-dev gulp-uglify different to npm install gulp-uglify

I am confused about the npm install process. 我对npm安装过程感到困惑。 From what I understand there are some different options for me when installing modules: 根据我的理解,安装模块时有一些不同的选择:

  • -g option that stores the modules globally -g选项,用于全局存储模块
  • --save-dev --save-dev的
  • no arguments. 没有争论。

Can someone explain what the differences are? 有人能解释一下差异是什么吗? Specifically when I do a -g (global) and another install locally does it get the modules from where I saved it globally? 特别是当我执行-g(全局)并在本地进行另一次安装时,它是否从全局保存模块中获取模块?

Also what does it mean by "--save: Package will appear in your dependencies." 另外,“ - save:Package会出现在你的依赖项中”是什么意思。

What dependencies is it talking about? 它在谈论什么依赖?

Okay. 好的。 So the thing is: 所以事情是:

  1. If you only want to install the dependency locally, then run: npm install gulp-uglify , and it will create a folder called node_modules, in which you will find the required module. 如果您只想在本地安装依赖项,则运行: npm install gulp-uglify uglify,它将创建一个名为node_modules的文件夹,您可以在其中找到所需的模块。
  2. If instead, you want to install the package globally, then you have to run: npm install -g gulp-uglify , that will allocate the package on your OS, and you will be able to use it anywhere (not only on that folder). 相反,如果你想全局安装软件包,那么你必须运行: npm install -g gulp-uglify ,它会在你的操作系统上分配软件包,你可以在任何地方使用它(不仅仅是在那个文件夹上) 。
  3. The option --save-dev (that will be npm install --save-dev gulp-uglify ) will also update your package.json file and it will be added as a dev dependency, which is your app manifesto. 选项--save-dev(将是npm install --save-dev gulp-uglify )也将更新你的package.json文件,它将被添加为dev依赖项,这是你的app宣言。 That means, on that file you will have declared all the dependencies that you will need on your project, and they will be installed just by running npm install . 这意味着,在该文件上,您将声明项目中需要的所有依赖项,并且只需运行npm install In order to create the package.json file, you have to run npm init . 要创建package.json文件,您必须运行npm init

More info can be found here . 更多信息可以在这里找到。 Or this other post . 或者这个帖子 Hope this helps! 希望这可以帮助!

-g puts the module in your global node_modules directory. -g将模块放在全局node_modules目录中。 These are available from any directory (hence global) 这些可从任何目录获得(因此全球)

--save-dev updates your package.json file to include the module as a dev dependency. --save-dev更新package.json文件以将模块包含为dev依赖项。 These are downloaded to your local node_modules folder for the directory. 这些将下载到目录的本地node_modules文件夹中。

No save argument updates your package.json file to include the module as a dependency. 没有save参数更新package.json文件以将模块包含为依赖项。 These are also downloaded to your local node_modules folder for the directory. 这些也会下载到目录的本地node_modules文件夹中。

devDependencies and dependencies have implications when somebody wants to install your project (via npm install). 当某人想安装你的项目时(通过npm install),devDependencies和依赖关系会产生影响。 For example, npm install will install all dependencies and devDependencies. 例如, npm install将安装所有依赖项和devDependencies。 npm install --production will not install devDependencies. npm install --production不会安装devDependencies。

So you would use --save-dev when the node module you are importing is used for development purposes and not runtime (eg maybe jshint to do a build). 因此,当您导入的节点模块用于开发目的而不是运行时(例如,可能使用jshint进行构建)时,您将使用--save-dev。 Modules that are needed for running your application should not use the --save-dev switch. 运行应用程序所需的模块不应使用--save-dev开关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM