我以爲全部程序員都在努力的學習閱讀英語吧,畢竟英語閱讀沒問題,咱們才能更好的閱讀文檔,爲了給你們更快的學習效率,因此翻譯了這一篇中英文對照的文章。若是你每次安裝package包時候會想,what?各類命令--save -D 之類的到底是什麼鬼?那麼能夠接着往下看了。
Install a package 安裝一個包前端
SYNOPSIS 簡介node
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文件,則依賴項的安裝將由此驅動,若是兩個文件都存在,則npm-shrinkwrap.json優先。 請參閱package-lock.json和npm-shrinkwrap。git
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 「latest」 tag satisfying (e)
g) a <git remote url> that resolves to (a)github
包裹是:shell
a)包含package.json文件描述的程序的文件夾
b)包含(a)的壓縮的tarball
c)解析爲(b)的網址
d)在註冊表上發佈的<name> @ <version>(參見npm-registry)(c)
e)指向(d)的<name> @ <tag>(參見npm-dist-tag)
f)具備知足(e)的「最新」標籤的<name>
g)解析爲(a)的<git remote url>npm
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).
即便您從未發佈過您的軟件包,若是您只想編寫一個節點程序(a),或者若是您還但願可以在打包以後輕鬆地將其安裝在其餘地方,那麼使用npm仍然能夠得到不少好處。 進入tarball(b)。json
npm install(在包目錄中,沒有參數):微信
Install the dependencies in the local node_modules folder.
在本地node_modules文件夾中安裝依賴項。app
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),它將當前包上下文(即當前工做目錄)安裝爲全局包。
By default, npm install will install all modules listed as dependencies in package.json.
默認狀況下,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標誌(或當NODE_ENV環境變量設置爲production時),npm將不會安裝devDependencies中列出的模塊。
NOTE: The --production flag has no particular meaning when adding a dependency to a project.
注意:向項目添加依賴項時, - production標誌沒有特別的意義。
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.
將包做爲當前項目中的符號連接安裝在目錄中。 它的依賴項將在連接以前安裝。 若是<folder>位於項目的根目錄內,則其依賴關係可能會升級到頂層node_modules,就像它們對其餘類型的依賴項同樣。
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.
安裝位於文件系統上的軟件包。 注意:若是您只想將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做爲擴展名。
包內容應該駐留在tarball內的子文件夾中(一般稱爲package /)。 npm在安裝軟件包時剝離一個目錄層(運行至關於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,而後安裝它。 爲了區分這個和其餘選項,參數必須以「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.
在大多數狀況下,這將在npm註冊表中安裝標記爲最新的模塊版本。
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默認將任何指定的包保存到依賴項中。 此外,您能夠經過一些額外的標誌來控制保存的位置和方式:
-P, --save-prod: Package will appear in your dependencies. This is the default unless -D or -O are present.
包將出如今您的依賴項中。 除非存在-D或-O,不然這是默認值。
-D, --save-dev: Package will appear in your devDependencies.
包將出如今您的devDependencies中。
-O, --save-optional: Package will appear in your optionalDependencies.
包將出如今您的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:
當使用上述任何選項來保存對package.json的依賴關係時,還有兩個額外的可選標誌:
-E, --save-exact: Saved dependencies will be configured with an exact version rather than using npm’s default semver range operator.
保存的依賴項將使用精確版本配置,而不是使用npm的默認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>是可選的。 該包將從與指定範圍關聯的註冊表中下載。 若是沒有與給定範圍關聯的註冊表,則假定使用默認註冊表。 請參閱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.
注意:若是當前工做目錄中存在名爲<name>的文件或文件夾,則它將嘗試安裝該文件或文件夾,而且只有在無效時才嘗試按名稱獲取程序包。
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.
安裝指定標記引用的包的版本。 若是該包的註冊表數據中不存在該標記,則此操做將失敗。
Example:
npm install sax@latest npm install @myorg/mypackage@latest
Install the specified version of the package. This will fail if the version has not been published to the registry.
安裝指定版本的軟件包。 若是版本還沒有發佈到註冊表,則會失敗。
Example:
npm install sax@0.1.1 npm install @myorg/privatepackage@1.5.0
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中描述的依賴關係的相同規則。
Note that most version ranges must be put in quotes so that your shell will treat it as a single argument.
請注意,大多數版本範圍必須放在引號中,以便shell將其視爲單個參數。
Example:
npm install sax@">=0.1.0 <0.2.0" npm install @myorg/privatepackage@">=0.1.0 <0.2.0"
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遠程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將查找遠程存儲庫中與該範圍匹配的任何標記或引用,就像它能夠 註冊表依賴項。 若是既未指定#<commit-ish>或#semver:<semver>,則使用存儲庫的默認分支。
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環境變量由npm識別,並在運行git時添加到環境中:
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... by attempting to clone it using git.
經過嘗試使用git克隆它,在https://github.com/githubname...。
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將查找遠程存儲庫中與該範圍匹配的任何標記或引用,就像它能夠 註冊表依賴項。 若是既未指定#<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.
與常規git依賴項同樣,若是程序包具備prepare腳本,則在安裝程序包以前將安裝依賴項和devDependencies。
Examples:
npm install mygithubuser/myproject npm install github:mygithubuser/myproject
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/gistI...。 與gist關聯的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.
與常規git依賴項同樣,若是程序包具備prepare腳本,則在安裝程序包以前將安裝依賴項和devDependencies。
Example:
npm install gist:101a11beef
Install the package at https://bitbucket.org/bitbuck... by attempting to clone it using git.
經過嘗試使用git克隆它,在https://bitbucket.org/bitbuck...。
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將查找遠程存儲庫中與該範圍匹配的任何標記或引用,就像它能夠 註冊表依賴項。 若是既未指定#<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.
與常規git依賴項同樣,若是程序包具備prepare腳本,則在安裝程序包以前將安裝依賴項和devDependencies。
Example:
npm install bitbucket:mybitbucketuser/myproject
Install the package at https://gitlab.com/gitlabname... by attempting to clone it using git.
經過嘗試使用git克隆它,在https://gitlab.com/gitlabname...。
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將查找遠程存儲庫中與該範圍匹配的任何標記或引用,就像它能夠 註冊表依賴項。 若是既未指定#<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.
與常規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:
您能夠組合多個參數,甚至多種類型的參數。 例如:
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參數將應用於全部指定的安裝目標。 若是存在具備給定名稱的標記,則標記版本優先於較新版本。
The --dry-run argument will report in the usual way what the install would have done without actually installing anything.
--dry-run參數將以一般的方式報告安裝將在沒有實際安裝任何內容的狀況下完成的操做。
The --package-lock-only argument will only update the package-lock.json, instead of checking node_modules and downloading dependencies.
--package-lock-only參數只會更新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參數也會強制npm獲取遠程資源。
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參數將致使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參數將致使npm將包安裝到本地node_modules文件夾中,其文件佈局與全局node_modules文件夾使用的佈局相同。 只有您的直接依賴項將顯示在node_modules中,它們所依賴的全部內容將在其node_modules文件夾中展平。 這顯然會消除一些重複數據刪除。
The --ignore-scripts argument will cause npm to not execute any scripts defined in the package.json. See npm-scripts.
--ignore-scripts參數將致使npm不執行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參數將致使npm安裝包,使得1.4以前的npm版本(例如節點0.8中包含的版本)能夠安裝包。 這消除了全部自動扣除。
The --link argument will cause npm to link global installs into the local space in some cases.
在某些狀況下, - link參數將致使npm將全局安裝連接到本地空間。
The --no-bin-links argument will prevent npm from creating symlinks for any binaries the package might contain.
--no-bin-links參數將阻止npm爲包可能包含的任何二進制文件建立符號連接。
The --no-optional argument will prevent optional dependencies from being installed.
--no-optional參數將阻止安裝可選的依賴項。
The --no-shrinkwrap argument, which will ignore an available package lock or shrinkwrap file and use the package.json instead.
--no-shrinkwrap參數,它將忽略可用的包鎖或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參數將阻止npm建立package-lock.json文件。 在使用package-lock運行時,npm在安裝時不會自動修剪節點模塊。
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參數將容許npm查找節點源代碼,以便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]}參數將致使僅安裝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參數可用於禁止將審計報告發送到已配置的註冊表。 有關發送內容的詳細信息,請參閱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。 許多配置參數對安裝有一些影響,由於這是npm的大部份內容。
本文首發於公衆號「前端的極致實現」。歡迎小可愛們來交流~加我微信(wangyuedewechat2)拉你們進羣