我覺得所有程序員都在努力的學(xué)習(xí)閱讀英語吧,畢竟英語閱讀沒問題韭山,我們才能更好的閱讀文檔郁季,為了給大家更快的學(xué)習(xí)效率,所以翻譯了這一篇中英文對照的文章钱磅。如果你每次安裝package包時候會想梦裂,what?各種命令--save -D 之類的究竟是什么鬼?那么可以接著往下看了盖淡。
npm-install
Install a package 安裝一個包
SYNOPSIS 簡介
npm install (with no args, in package dir)
npm install [<@scope>/]<name>
npm install [<@scope>/]<name>@<tag>
npm install [<@scope>/]<name>@<version>
npm install [<@scope>/]<name>@<version range>
npm install <git-host>:<git-user>/<repo-name>
npm install <git repo url>
npm install <tarball file>
npm install <tarball url>
npm install <folder>
aliases: npm i, npm add
別名:npm i, npm add
common options: [-P|--save-prod|-D|--save-dev|-O|--save-optional] [-E|--save-exact] [-B|--save-bundle] [--no-save] [--dry-run]
DESCRIPTION 描述
This command installs a package, and any packages that it depends on. If the package has a package-lock or shrinkwrap file, the installation of dependencies will be driven by that, with an npm-shrinkwrap.json taking precedence if both files exist. See package-lock.json and npm-shrinkwrap.
此命令將安裝程序包及其依賴的任何程序包年柠。 如果軟件包具有package-lock或shrinkwrap文件,則依賴項的安裝將由此驅(qū)動褪迟,如果兩個文件都存在彪杉,則npm-shrinkwrap.json優(yōu)先。 請參閱package-lock.json和npm-shrinkwrap牵咙。
A package is:
a) a folder containing a program described by a package.json file
b) a gzipped tarball containing (a)
c) a url that resolves to (b)
d) a <name>@<version> that is published on the registry (see npm-registry) with (c)
e) a <name>@<tag> (see npm-dist-tag) that points to (d)
f) a <name> that has a “l(fā)atest” tag satisfying (e)
g) a <git remote url> that resolves to (a)
包裹是:
a)包含package.json文件描述的程序的文件夾
b)包含(a)的壓縮的tarball
c)解析為(b)的網(wǎng)址
d)在注冊表上發(fā)布的<name> @ <version>(參見npm-registry)(c)
e)指向(d)的<name> @ <tag>(參見npm-dist-tag)
f)具有滿足(e)的“最新”標(biāo)簽的<name>
g)解析為(a)的<git remote url>
Even if you never publish your package, you can still get a lot of benefits of using npm if you just want to write a node program (a), and perhaps if you also want to be able to easily install it elsewhere after packing it up into a tarball (b).
即使您從未發(fā)布過您的軟件包派近,如果您只想編寫一個節(jié)點程序(a),或者如果您還希望能夠在打包之后輕松地將其安裝在其他地方洁桌,那么使用npm仍然可以獲得很多好處渴丸。 進(jìn)入tarball(b)。
npm install (in package directory, no arguments):
npm install(在包目錄中另凌,沒有參數(shù)):
Install the dependencies in the local node_modules folder.
在本地node_modules文件夾中安裝依賴項谱轨。
In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package.
在全局模式下(即,在命令后附加-g或--global)吠谢,它將當(dāng)前包上下文(即當(dāng)前工作目錄)安裝為全局包土童。
By default, npm install will install all modules listed as dependencies in package.json.
默認(rèn)情況下,npm install將在package.json中安裝列為依賴項的所有模塊工坊。
With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies.
使用--production標(biāo)志(或當(dāng)NODE_ENV環(huán)境變量設(shè)置為production時)献汗,npm將不會安裝devDependencies中列出的模塊。
NOTE: The --production flag has no particular meaning when adding a dependency to a project.
注意:向項目添加依賴項時王污, - production標(biāo)志沒有特別的意義罢吃。
npm install <folder>:
npm install 文件夾
Install the package in the directory as a symlink in the current project. Its dependencies will be installed before it’s linked. If <folder> sits inside the root of your project, its dependencies may be hoisted to the toplevel node_modules as they would for other types of dependencies.
將包作為當(dāng)前項目中的符號鏈接安裝在目錄中。 它的依賴項將在鏈接之前安裝昭齐。 如果<folder>位于項目的根目錄內(nèi)尿招,則其依賴關(guān)系可能會升級到頂層node_modules,就像它們對其他類型的依賴項一樣。
npm install <tarball file>:
Install a package that is sitting on the filesystem. Note: if you just want to link a dev directory into your npm root, you can do this more easily by using npm link.
安裝位于文件系統(tǒng)上的軟件包就谜。 注意:如果您只想將dev目錄鏈接到npm根目錄怪蔑,則可以使用npm link更輕松地完成此操作。
Tarball requirements:
The filename must use .tar, .tar.gz, or .tgz as the extension.
The package contents should reside in a subfolder inside the tarball (usually it is called package/). npm strips one directory layer when installing the package (an equivalent of tar x --strip-components=1 is run).
The package must contain a package.json file with name and version properties.
文件名必須使用.tar丧荐,.tar.gz或.tgz作為擴(kuò)展名缆瓣。
包內(nèi)容應(yīng)該駐留在tarball內(nèi)的子文件夾中(通常稱為package /)。 npm在安裝軟件包時剝離一個目錄層(運行相當(dāng)于tar x --strip-components = 1)篮奄。
該包必須包含具有名稱和版本屬性的package.json文件捆愁。
Example:
npm install ./package.tgz
npm install <tarball url>:
Fetch the tarball url, and then install it. In order to distinguish between this and other options, the argument must start with “http://” or “https://”
獲取tarball URL割去,然后安裝它窟却。 為了區(qū)分這個和其他選項,參數(shù)必須以“http://”或“https://”開頭呻逆。
Example:
npm install https://github.com/indexzero/forever/tarball/v0.5.6
npm install [<@scope>/]<name>:
Do a <name>@<tag> install, where <tag> is the “tag” config. (See npm-config. The config’s default value is latest.)
In most cases, this will install the version of the modules tagged as latest on the npm registry.
在大多數(shù)情況下夸赫,這將在npm注冊表中安裝標(biāo)記為最新的模塊版本。
Example:
npm install sax
npm install saves any specified packages into dependencies by default. Additionally, you can control where and how they get saved with some additional flags:
npm install默認(rèn)將任何指定的包保存到依賴項中咖城。 此外茬腿,您可以通過一些額外的標(biāo)志來控制保存的位置和方式:
-P, --save-prod: Package will appear in your dependencies. This is the default unless -D or -O are present.
包將出現(xiàn)在您的依賴項中。 除非存在-D或-O宜雀,否則這是默認(rèn)值切平。
-D, --save-dev: Package will appear in your devDependencies.
包將出現(xiàn)在您的devDependencies中。
-O, --save-optional: Package will appear in your optionalDependencies.
包將出現(xiàn)在您的optionalDependencies中辐董。
--no-save: Prevents saving to dependencies.
防止保存到依賴項悴品。
When using any of the above options to save dependencies to your package.json, there are two additional, optional flags:
當(dāng)使用上述任何選項來保存對package.json的依賴關(guān)系時,還有兩個額外的可選標(biāo)志:
-E, --save-exact: Saved dependencies will be configured with an exact version rather than using npm’s default semver range operator.
保存的依賴項將使用精確版本配置简烘,而不是使用npm的默認(rèn)semver范圍運算符苔严。
-B, --save-bundle: Saved dependencies will also be added to your bundleDependencies list.
保存的依賴項也將添加到您的bundleDependencies列表中。
Further, if you have an npm-shrinkwrap.json or package-lock.json then it will be updated as well.
此外孤澎,如果你有一個npm-shrinkwrap.json或package-lock.json届氢,那么它也會被更新。
<scope> is optional. The package will be downloaded from the registry associated with the specified scope. If no registry is associated with the given scope the default registry is assumed. See npm-scope.
<scope>是可選的覆旭。 該包將從與指定范圍關(guān)聯(lián)的注冊表中下載退子。 如果沒有與給定范圍關(guān)聯(lián)的注冊表,則假定使用默認(rèn)注冊表型将。 請參閱npm-scope絮供。
Note: if you do not include the @-symbol on your scope name, npm will interpret this as a GitHub repository instead, see below. Scopes names must also be followed by a slash.
注意:如果您沒有在范圍名稱中包含@ -symbol,則npm會將其解釋為GitHub存儲庫茶敏,請參閱下文壤靶。 范圍名稱后面還必須有斜杠。
Examples:
npm install sax
npm install githubname/reponame
npm install @myorg/privatepackage
npm install node-tap --save-dev
npm install dtrace-provider --save-optional
npm install readable-stream --save-exact
npm install ansi-regex --save-bundle
Note: If there is a file or folder named <name> in the current working directory, then it will try to install that, and only try to fetch the package by name if it is not valid.
注意:如果當(dāng)前工作目錄中存在名為<name>的文件或文件夾惊搏,則它將嘗試安裝該文件或文件夾贮乳,并且只有在無效時才嘗試按名稱獲取程序包忧换。
npm install [<@scope>/]<name>@<tag>:
Install the version of the package that is referenced by the specified tag. If the tag does not exist in the registry data for that package, then this will fail.
安裝指定標(biāo)記引用的包的版本。 如果該包的注冊表數(shù)據(jù)中不存在該標(biāo)記向拆,則此操作將失敗亚茬。
Example:
npm install sax@latest
npm install @myorg/mypackage@latest
- npm install [<@scope>/]<name>@<version>:
Install the specified version of the package. This will fail if the version has not been published to the registry.
安裝指定版本的軟件包。 如果版本尚未發(fā)布到注冊表浓恳,則會失敗刹缝。
Example:
npm install sax@0.1.1
npm install @myorg/privatepackage@1.5.0
- npm install [<@scope>/]<name>@<version range>:
Install a version of the package matching the specified version range. This will follow the same rules for resolving dependencies described in package.json.
安裝與指定版本范圍匹配的軟件包版本。 這將遵循解決package.json中描述的依賴關(guān)系的相同規(guī)則颈将。
Note that most version ranges must be put in quotes so that your shell will treat it as a single argument.
請注意梢夯,大多數(shù)版本范圍必須放在引號中,以便shell將其視為單個參數(shù)晴圾。
Example:
npm install sax@">=0.1.0 <0.2.0"
npm install @myorg/privatepackage@">=0.1.0 <0.2.0"
- npm install <git remote url>:
Installs the package from the hosted git provider, cloning it with git. For a full git remote url, only that URL will be attempted.
從托管的git提供程序安裝包颂砸,使用git克隆它。 對于完整的git遠(yuǎn)程URL死姚,只會嘗試該URL人乓。
<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]
<protocol> is one of git, git+ssh, git+http, git+https, or git+file.
If #<commit-ish> is provided, it will be used to clone exactly that commit. If the commit-ish has the format #semver:<semver>, <semver> can be any valid semver range or exact version, and npm will look for any tags or refs matching that range in the remote repository, much as it would for a registry dependency. If neither #<commit-ish> or #semver:<semver> is specified, then the default branch of the repository is used.
如果提供了#<commit-ish>,它將用于完全克隆該提交都毒。 如果commit-ish的格式為#semver:<semver>色罚,則<semver>可以是任何有效的semver范圍或精確版本,npm將查找遠(yuǎn)程存儲庫中與該范圍匹配的任何標(biāo)記或引用账劲,就像它可以 注冊表依賴項戳护。 如果既未指定#<commit-ish>或#semver:<semver>,則使用存儲庫的默認(rèn)分支涤垫。
If the repository makes use of submodules, those submodules will be cloned as well.
如果存儲庫使用子模塊姑尺,那么也將克隆這些子模塊。
If the package being installed contains a prepare script, its dependencies and devDependencies will be installed, and the prepare script will be run, before the package is packaged and installed.
如果正在安裝的軟件包包含一個prepare腳本蝠猬,則將安裝其依賴項和devDependencies切蟋,并在打包和安裝軟件包之前運行prepare腳本。
The following git environment variables are recognized by npm and will be added to the environment when running git:
以下git環(huán)境變量由npm識別榆芦,并在運行g(shù)it時添加到環(huán)境中:
GIT_ASKPASS
GIT_EXEC_PATH
GIT_PROXY_COMMAND
GIT_SSH
GIT_SSH_COMMAND
GIT_SSL_CAINFO
GIT_SSL_NO_VERIFY
See the git man page for details.
Examples:
npm install git+ssh://git@github.com:npm/cli.git#v1.0.27
npm install git+ssh://git@github.com:npm/cli#semver:^5.0
npm install git+https://isaacs@github.com/npm/cli.git
npm install git://github.com/npm/cli.git#v1.0.27
GIT_SSH_COMMAND='ssh -i ~/.ssh/custom_ident' npm install git+ssh://git@github.com:npm/cli.git
npm install <githubname>/<githubrepo>[#<commit-ish>]:
npm install github:<githubname>/<githubrepo>[#<commit-ish>]:
Install the package at https://github.com/githubname/githubrepo by attempting to clone it using git.
通過嘗試使用git克隆它柄粹,在https://github.com/githubname/githubrepo安裝軟件包。
If #<commit-ish> is provided, it will be used to clone exactly that commit. If the commit-ish has the format #semver:<semver>, <semver> can be any valid semver range or exact version, and npm will look for any tags or refs matching that range in the remote repository, much as it would for a registry dependency. If neither #<commit-ish> or #semver:<semver> is specified, then master is used.
如果提供了#<commit-ish>匆绣,它將用于完全克隆該提交驻右。 如果commit-ish的格式為#semver:<semver>,則<semver>可以是任何有效的semver范圍或精確版本崎淳,npm將查找遠(yuǎn)程存儲庫中與該范圍匹配的任何標(biāo)記或引用堪夭,就像它可以 注冊表依賴項。 如果既未指定#<commit-ish>或#semver:<semver>,則使用master森爽。
As with regular git dependencies, dependencies and devDependencies will be installed if the package has a prepare script, before the package is done installing.
與常規(guī)git依賴項一樣恨豁,如果程序包具有prepare腳本,則在安裝程序包之前將安裝依賴項和devDependencies爬迟。
Examples:
npm install mygithubuser/myproject
npm install github:mygithubuser/myproject
- npm install gist:[<githubname>/]<gistID>[#<commit-ish>|#semver:<semver>]:
Install the package at https://gist.github.com/gistID by attempting to clone it using git. The GitHub username associated with the gist is optional and will not be saved in package.json.
通過嘗試使用git克隆它橘蜜,在https://gist.github.com/gistID上安裝軟件包。 與gist關(guān)聯(lián)的GitHub用戶名是可選的付呕,不會保存在package.json中计福。
As with regular git dependencies, dependencies and devDependencies will be installed if the package has a prepare script, before the package is done installing.
與常規(guī)git依賴項一樣,如果程序包具有prepare腳本徽职,則在安裝程序包之前將安裝依賴項和devDependencies象颖。
Example:
npm install gist:101a11beef
- npm install bitbucket:<bitbucketname>/<bitbucketrepo>[#<commit-ish>]:
Install the package at https://bitbucket.org/bitbucketname/bitbucketrepo by attempting to clone it using git.
通過嘗試使用git克隆它,在https://bitbucket.org/bitbucketname/bitbucketrepo安裝軟件包活箕。
If #<commit-ish> is provided, it will be used to clone exactly that commit. If the commit-ish has the format #semver:<semver>, <semver> can be any valid semver range or exact version, and npm will look for any tags or refs matching that range in the remote repository, much as it would for a registry dependency. If neither #<commit-ish> or #semver:<semver> is specified, then master is used.
如果提供了#<commit-ish>力麸,它將用于完全克隆該提交可款。 如果commit-ish的格式為#semver:<semver>育韩,則<semver>可以是任何有效的semver范圍或精確版本,npm將查找遠(yuǎn)程存儲庫中與該范圍匹配的任何標(biāo)記或引用闺鲸,就像它可以 注冊表依賴項筋讨。 如果既未指定#<commit-ish>或#semver:<semver>,則使用master摸恍。
As with regular git dependencies, dependencies and devDependencies will be installed if the package has a prepare script, before the package is done installing.
與常規(guī)git依賴項一樣悉罕,如果程序包具有prepare腳本,則在安裝程序包之前將安裝依賴項和devDependencies立镶。
Example:
npm install bitbucket:mybitbucketuser/myproject
- npm install gitlab:<gitlabname>/<gitlabrepo>[#<commit-ish>]:
Install the package at https://gitlab.com/gitlabname/gitlabrepo by attempting to clone it using git.
通過嘗試使用git克隆它壁袄,在https://gitlab.com/gitlabname/gitlabrepo安裝軟件包。
If #<commit-ish> is provided, it will be used to clone exactly that commit. If the commit-ish has the format #semver:<semver>, <semver> can be any valid semver range or exact version, and npm will look for any tags or refs matching that range in the remote repository, much as it would for a registry dependency. If neither #<commit-ish> or #semver:<semver> is specified, then master is used.
如果提供了#<commit-ish>媚媒,它將用于完全克隆該提交嗜逻。 如果commit-ish的格式為#semver:<semver>,則<semver>可以是任何有效的semver范圍或精確版本缭召,npm將查找遠(yuǎn)程存儲庫中與該范圍匹配的任何標(biāo)記或引用栈顷,就像它可以 注冊表依賴項。 如果既未指定#<commit-ish>或#semver:<semver>嵌巷,則使用master萄凤。
As with regular git dependencies, dependencies and devDependencies will be installed if the package has a prepare script, before the package is done installing.
與常規(guī)git依賴項一樣,如果程序包具有prepare腳本搪哪,則在安裝程序包之前將安裝依賴項和devDependencies靡努。
Example:
npm install gitlab:mygitlabuser/myproject
npm install gitlab:myusr/myproj#semver:^5.0
You may combine multiple arguments, and even multiple types of arguments. For example:
您可以組合多個參數(shù),甚至多種類型的參數(shù)。 例如:
npm install sax@">=0.1.0 <0.2.0" bench supervisor
The --tag argument will apply to all of the specified install targets. If a tag with the given name exists, the tagged version is preferred over newer versions.
--tag參數(shù)將應(yīng)用于所有指定的安裝目標(biāo)惑朦。 如果存在具有給定名稱的標(biāo)記神年,則標(biāo)記版本優(yōu)先于較新版本。
The --dry-run argument will report in the usual way what the install would have done without actually installing anything.
--dry-run參數(shù)將以通常的方式報告安裝將在沒有實際安裝任何內(nèi)容的情況下完成的操作行嗤。
The --package-lock-only argument will only update the package-lock.json, instead of checking node_modules and downloading dependencies.
--package-lock-only參數(shù)只會更新package-lock.json已日,而不是檢查node_modules和下載依賴項
The -f or --force argument will force npm to fetch remote resources even if a local copy exists on disk.
即使磁盤上存在本地副本,-f或--force參數(shù)也會強制npm獲取遠(yuǎn)程資源栅屏。
npm install sax --force
The -g or --global argument will cause npm to install the package globally rather than locally. See npm-folders.
-g或--global參數(shù)將導(dǎo)致npm全局安裝包而不是本地安裝包飘千。 請參閱npm-folders。
The --global-style argument will cause npm to install the package into your local node_modules folder with the same layout it uses with the global node_modules folder. Only your direct dependencies will show in node_modules and everything they depend on will be flattened in their node_modules folders. This obviously will eliminate some deduping.
--global-style參數(shù)將導(dǎo)致npm將包安裝到本地node_modules文件夾中栈雳,其文件布局與全局node_modules文件夾使用的布局相同护奈。 只有您的直接依賴項將顯示在node_modules中,它們所依賴的所有內(nèi)容將在其node_modules文件夾中展平哥纫。 這顯然會消除一些重復(fù)數(shù)據(jù)刪除霉旗。
The --ignore-scripts argument will cause npm to not execute any scripts defined in the package.json. See npm-scripts.
--ignore-scripts參數(shù)將導(dǎo)致npm不執(zhí)行package.json中定義的任何腳本。 請參閱npm-scripts蛀骇。
The --legacy-bundling argument will cause npm to install the package such that versions of npm prior to 1.4, such as the one included with node 0.8, can install the package. This eliminates all automatic deduping.
--legacy-bundling參數(shù)將導(dǎo)致npm安裝包厌秒,使得1.4之前的npm版本(例如節(jié)點0.8中包含的版本)可以安裝包。 這消除了所有自動扣除擅憔。
The --link argument will cause npm to link global installs into the local space in some cases.
在某些情況下鸵闪, - link參數(shù)將導(dǎo)致npm將全局安裝鏈接到本地空間。
The --no-bin-links argument will prevent npm from creating symlinks for any binaries the package might contain.
--no-bin-links參數(shù)將阻止npm為包可能包含的任何二進(jìn)制文件創(chuàng)建符號鏈接暑诸。
The --no-optional argument will prevent optional dependencies from being installed.
--no-optional參數(shù)將阻止安裝可選的依賴項蚌讼。
The --no-shrinkwrap argument, which will ignore an available package lock or shrinkwrap file and use the package.json instead.
--no-shrinkwrap參數(shù),它將忽略可用的包鎖或shrinkwrap文件个榕,而是使用package.json篡石。
The --no-package-lock argument will prevent npm from creating a package-lock.json file. When running with package-lock’s disabled npm will not automatically prune your node modules when installing.
--no-package-lock參數(shù)將阻止npm創(chuàng)建package-lock.json文件。 在使用package-lock運行時西采,npm在安裝時不會自動修剪節(jié)點模塊凰萨。
The --nodedir=/path/to/node/source argument will allow npm to find the node source code so that npm can compile native modules.
--nodedir = / path / to / node / source參數(shù)將允許npm查找節(jié)點源代碼,以便npm可以編譯本機模塊苛让。
The --only={prod[uction]|dev[elopment]} argument will cause either only devDependencies or only non-devDependencies to be installed regardless of the NODE_ENV.
--only = {prod [uction] | dev [elopment]}參數(shù)將導(dǎo)致僅安裝devDependencies或僅安裝非devDependencies沟蔑,而不管NODE_ENV如何。
The --no-audit argument can be used to disable sending of audit reports to the configured registries. See npm-audit for details on what is sent.
--no-audit參數(shù)可用于禁止將審計報告發(fā)送到已配置的注冊表狱杰。 有關(guān)發(fā)送內(nèi)容的詳細(xì)信息瘦材,請參閱npm-audit。
See npm-config. Many of the configuration params have some effect on installation, since that’s most of what npm does.
請參閱npm-config仿畸。 許多配置參數(shù)對安裝有一些影響食棕,因為這是npm的大部分內(nèi)容朗和。
本文首發(fā)于公眾號“前端的極致實現(xiàn)”。歡迎小可愛們來交流~加我微信(wangyuedewechat2)拉大家進(jìn)群