npm install的--save选项是什么?

本文翻译自:What is the --save option for npm install?

I saw some tutorial where the command was: 我看到了一些命令所在的教程:

npm install --save

What does the --save option mean? --save选项是什么意思?

Not able to find the answer on Google. 在Google上找不到答案。


#1楼

参考:https://stackoom.com/question/1K9L2/npm-install的-save选项是什么


#2楼

Update npm 5: 更新npm 5:

As of npm 5.0.0 , installed modules are added as a dependency by default, so the --save option is no longer needed. npm 5.0.0开始 ,默认情况下已安装的模块作为依赖项添加,因此不再需要--save选项。 The other save options still exist and are listed in the documentation for npm install . 其他保存选项仍然存在,并在npm install文档中列出。

Original answer: 原始答案:

Before version 5, NPM simply installed a package under node_modules by default. 在版本5之前,默认情况下,NPM只是在node_modules下安装了一个软件包。 When you were trying to install dependencies for your app/module, you would need to first install them, and then add them (along with the appropriate version number) to the dependencies section of your package.json . 当您尝试为应用程序/模块安装依赖项时,您需要先安装它们,然后将它们(以及适当的版本号)添加到package.jsondependencies部分。

The --save option instructed NPM to include the package inside of the dependencies section of your package.json automatically, thus saving you an additional step. --save选项指示NPM自动将软件包包括在package.jsondependencies部分中,从而为您节省了额外的步骤。

In addition, there are the complementary options --save-dev and --save-optional which save the package under devDependencies and optionalDependencies , respectively. 此外,还有补充选项--save-dev--save-optional ,它们分别将软件包保存在devDependenciesoptionalDependencies下。 This is useful when installing development-only packages, like grunt or your testing library. 在安装仅限开发的软件包(例如grunt或测试库)时,这很有用。


#3楼

It won't do anything if you don't have a package.json file. 如果没有package.json文件,它将不会执行任何操作。 Start by running npm init to create one. 首先运行npm init创建一个。 Then calls to npm install --save or npm install --save-dev or npm install --save-optional will update the package.json to list your dependencies. 然后调用npm install --savenpm install --save-devnpm install --save-optional将更新package.json以列出您的依赖项。


#4楼

To add package in dependencies: 要添加依赖包:

npm install my_dep --save

or 要么

npm install my_dep -S

or 要么

npm i my_dep -S

To add package in devDependencies 在devDependencies中添加软件包

npm install my_test_framework --save-dev

or 要么

npm install my_test_framework -D

or 要么

npm i my_test_framework -D

package.json package.json 在此处输入图片说明


#5楼

You can also use -S , -D or -P which are equivalent of saving the package to an app dependency, a dev dependency or prod dependency. 您还可以使用-S-D-P ,它们等效于将程序包保存为应用程序依赖,开发人员依赖或产品依赖。 See more NPM shortcuts below: 请在下面查看更多NPM快捷方式:

-v: --version
-h, -?, --help, -H: --usage
-s, --silent: --loglevel silent
-q, --quiet: --loglevel warn
-d: --loglevel info
-dd, --verbose: --loglevel verbose
-ddd: --loglevel silly
-g: --global
-C: --prefix
-l: --long
-m: --message
-p, --porcelain: --parseable
-reg: --registry
-f: --force
-desc: --description
-S: --save
-P: --save-prod
-D: --save-dev
-O: --save-optional
-B: --save-bundle
-E: --save-exact
-y: --yes
-n: --yes false
ll and la commands: ls --long

This list of shortcuts can be obtained by running the following command: 可以通过运行以下命令获取此快捷方式列表:

$ npm help 7 config

#6楼

npm install package_x --save

The given package (package_x) will be saved in package.json inside dependencies. 给定的包(package_x)将保存在依赖关系内的package.json中。 if you add 如果您添加

npm install <<package_x>> --save-dev

then it will be saved inside devDependencies . 然后将其保存在devDependencies中

发布了0 篇原创文章 · 获赞 72 · 访问量 54万+

猜你喜欢

转载自blog.csdn.net/w36680130/article/details/105194210