Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
470 views
in Technique[技术] by (71.8m points)

node.js - 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上找不到答案。)

  ask by Dmitri translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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或测试库)时,这很有用。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...