资讯专栏INFORMATION COLUMN

npm官方npm-install文档翻译

RobinQu / 832人阅读

摘要:如果版本尚未发布到注册表,则会失败。参数将阻止安装可选的依赖项。参数,它将忽略可用的包锁或文件,而是使用。参数可用于禁止将审计报告发送到已配置的注册表。

我觉得所有程序员都在努力的学习阅读英语吧,毕竟英语阅读没问题,我们才能更好的阅读文档,为了给大家更快的学习效率,所以翻译了这一篇中英文对照的文章。如果你每次安装package包时候会想,what?各种命令--save  -D 之类的究竟是什么鬼?那么可以接着往下看了。
npm-install

Install a package 安装一个包

SYNOPSIS 简介

npm install (with no args, in package dir)
npm install [<@scope>/]
npm install [<@scope>/]@
npm install [<@scope>/]@
npm install [<@scope>/]@
npm install :/
npm install 
npm install 
npm install 
npm install 

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。

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 @ that is published on the registry (see npm-registry) with (c)
e) a @ (see npm-dist-tag) that points to (d)
f) a that has a “latest” tag satisfying (e)
g) a that resolves to (a)

包裹是:

a)包含package.json文件描述的程序的文件夹
b)包含(a)的压缩的tarball
c)解析为(b)的网址
d)在注册表上发布的 @ (参见npm-registry)(c)
e)指向(d)的 @ (参见npm-dist-tag)
f)具有满足(e)的“最新”标签的
g)解析为(a)的

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)。

npm install (in package directory, no arguments):

npm install(在包目录中,没有参数):

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),它将当前包上下文(即当前工作目录)安装为全局包。

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 :

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 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.
将包作为当前项目中的符号链接安装在目录中。 它的依赖项将在链接之前安装。 如果位于项目的根目录内,则其依赖关系可能会升级到顶层node_modules,就像它们对其他类型的依赖项一样。

npm install :

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 :

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>/]:

Do a @ install, where 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,那么它也会被更新。

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.
是可选的。 该包将从与指定范围关联的注册表中下载。 如果没有与给定范围关联的注册表,则假定使用默认注册表。 请参阅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 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.
注意:如果当前工作目录中存在名为的文件或文件夹,则它将尝试安装该文件或文件夹,并且只有在无效时才尝试按名称获取程序包。

npm install [<@scope>/]@:

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

npm install [<@scope>/]@:

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

npm install [<@scope>/]@:

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"

npm install :

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。

://[[:]@][:][:][/][# | #semver:]

is one of git, git+ssh, git+http, git+https, or git+file.

If # is provided, it will be used to clone exactly that commit. If the commit-ish has the format #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 # or #semver: is specified, then the default branch of the repository is used.
如果提供了#,它将用于完全克隆该提交。 如果commit-ish的格式为#semver:,则可以是任何有效的semver范围或精确版本,npm将查找远程存储库中与该范围匹配的任何标记或引用,就像它可以 注册表依赖项。 如果既未指定#或#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 /[#]:
npm install github:/[#]:

Install the package at https://github.com/githubname... by attempting to clone it using git.
通过尝试使用git克隆它,在https://github.com/githubname...。

If # is provided, it will be used to clone exactly that commit. If the commit-ish has the format #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 # or #semver: is specified, then master is used.
如果提供了#,它将用于完全克隆该提交。 如果commit-ish的格式为#semver:,则可以是任何有效的semver范围或精确版本,npm将查找远程存储库中与该范围匹配的任何标记或引用,就像它可以 注册表依赖项。 如果既未指定#或#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

npm install gist:[/][#|#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/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

npm install bitbucket:/[#]:

Install the package at https://bitbucket.org/bitbuck... by attempting to clone it using git.
通过尝试使用git克隆它,在https://bitbucket.org/bitbuck...。

If # is provided, it will be used to clone exactly that commit. If the commit-ish has the format #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 # or #semver: is specified, then master is used.
如果提供了#,它将用于完全克隆该提交。 如果commit-ish的格式为#semver:,则可以是任何有效的semver范围或精确版本,npm将查找远程存储库中与该范围匹配的任何标记或引用,就像它可以 注册表依赖项。 如果既未指定#或#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

npm install gitlab:/[#]:

Install the package at https://gitlab.com/gitlabname... by attempting to clone it using git.
通过尝试使用git克隆它,在https://gitlab.com/gitlabname...。

If # is provided, it will be used to clone exactly that commit. If the commit-ish has the format #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 # or #semver: is specified, then master is used.
如果提供了#,它将用于完全克隆该提交。 如果commit-ish的格式为#semver:,则可以是任何有效的semver范围或精确版本,npm将查找远程存储库中与该范围匹配的任何标记或引用,就像它可以 注册表依赖项。 如果既未指定#或#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)拉大家进群

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/106324.html

相关文章

  • 代码组织和部署 文件操作 node.js

    代码组织和部署 模块的路径解析规则 require支持/或者盘符的绝对路径,也支持./开头的相对地址同时require也支持第三种写法 内置模块 如果传递给require的函数是node.js的内置模块,将会不做路径解析,直接返回内部exports模块要导出的对象 node_modules目录 node.js定义一个node_modules存放模块,每次使用foo/bar的方式的时候,会先寻找该目...

    Cc_2011 评论0 收藏0
  • React项目实战:环境搭建

    摘要:官方文档中文翻译构建用户界面的库。官方文档建议学习时以官方文档为准,中文翻译或者第三方作者的教程可以帮助你理清思路会用到的重要知识点我也会进行简明的解释,如遇到错误或者不理解的内容,欢迎实时指出。 前言 前面提到前端大统一的概念,如果感兴趣,欢迎说说自己的看法,点击前往。Web前端框架层出不穷,不可能面面俱到,这里给个小建议: 如果对Weex App感兴趣,应该选择vue框架; 如果...

    cnio 评论0 收藏0
  • React项目实战:环境搭建

    摘要:官方文档中文翻译构建用户界面的库。官方文档建议学习时以官方文档为准,中文翻译或者第三方作者的教程可以帮助你理清思路会用到的重要知识点我也会进行简明的解释,如遇到错误或者不理解的内容,欢迎实时指出。 前言 前面提到前端大统一的概念,如果感兴趣,欢迎说说自己的看法,点击前往。Web前端框架层出不穷,不可能面面俱到,这里给个小建议: 如果对Weex App感兴趣,应该选择vue框架; 如果...

    GHOST_349178 评论0 收藏0
  • Linux下node-sass安装失败的解决方法与简单使用

    摘要:此后,全局安装的模块都会安装在这个子目录中,也会到目录去寻找命令。最后,将这个路径在文件或文件中加入变量。 记录一下安装node-sass的过程.关于CSS是不是一门编程语言,这里不讨论,但是它没有变量 语句 函数(反正我觉得他不是编程语言).于是程序员们发明了CSS预处理器(css preprocessor),它是一种专门的编程语言,可以使用你会的基本的编程知识进行编程,然后再转化成...

    cnio 评论0 收藏0
  • Linux下node-sass安装失败的解决方法与简单使用

    摘要:此后,全局安装的模块都会安装在这个子目录中,也会到目录去寻找命令。最后,将这个路径在文件或文件中加入变量。 记录一下安装node-sass的过程.关于CSS是不是一门编程语言,这里不讨论,但是它没有变量 语句 函数(反正我觉得他不是编程语言).于是程序员们发明了CSS预处理器(css preprocessor),它是一种专门的编程语言,可以使用你会的基本的编程知识进行编程,然后再转化成...

    syoya 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<