我看到了一些教程,其中的命令是:

npm install --save

--save选项是什么意思?


当前回答

当您在npm命令中使用--save来安装包时,这意味着您的项目将在生产环境中安装这些依赖项,例如,如果您安装了一个库来管理日期。

npm install moment --save
npm i moment -S (same result)

(这适用于生产环境)

npm install moment --save--dev
npm i moment -D (same result)

(这是用于开发环境)

其他回答

npm install package_x—保存

给定的包(package_x)将保存在依赖项内的package.json中。如果您添加

npm安装<<package_x>>--保存设备

那么它将保存在devDependencies中。

npm i(程序包名称)--保存

简单地说,使用上面的命令,我们不需要在package.json文件中写入包名,它将自动添加其名称和依赖项,以及您在开始生产或设置其他时间所需的版本。

npm帮助安装

上面的命令将有助于查找更多选项并更正图片中的def.shown:

您还可以使用-S、-D或-P,这相当于将包保存为应用程序依赖项、开发依赖项或生产依赖项。查看以下更多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

可以通过运行以下命令获得此快捷方式列表:

npm help 7 config

–npm install--save或-S:当以下命令与npm安装一起使用时,这会将所有已安装的核心包保存到package.json文件的依赖部分中。核心依赖项是那些应用程序无法提供所需结果的包。

但如前所述,在npm 5.0.0版本之后,这是一个不必要的功能。

npm install --save

npm v6.x更新

现在,您可以使用npm i或npm i-S或npm i-P之一来安装模块并将其保存为依赖项。

npm i是npm install的别名

npm i等于npm install,这意味着默认的save模块是一个依赖项;npm i-S等于npm install--save(npm v5-)npm i-P等于npm install--save prod(npm v5+)

查看您的npm版本

npm -v

6.14.4

获取npm-cli帮助信息

npm -h

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, fund, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

Specify configs in the ini-formatted file:
    /Users/xgqfrms-mbp/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@6.14.4 /Users/xgqfrms-mbp/.nvm/versions/node/v12.18.0/lib/node_modules/npm

获取npm安装帮助

npm帮助安装别名npm-h i

npm help install

# OR, alias
npm -h i

输出:

npm install (with no args, in package dir)
npm install [<@scope>/]<pkg>
npm install [<@scope>/]<pkg>@<tag>
npm install [<@scope>/]<pkg>@<version>
npm install [<@scope>/]<pkg>@<version range>
npm install <alias>@npm:<name>
npm install <folder>
npm install <tarball file>
npm install <tarball url>
npm install <git:// url>
npm install <github username>/<github project>

aliases: i, isntall, add
common options: [--save-prod|--save-dev|--save-optional] [--save-exact] [--no-save]
➜  ~

工具书类

npm安装