npm-install
选择命令行版本:
See Details
目录
概要
¥Synopsis
npm install [<package-spec> ...]aliases: add, i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall
描述
¥Description
此命令安装一个包和它所依赖的任何包。如果包有一个包锁,或者一个 npm 收缩封装文件,或者一个 Yarn 锁文件,依赖的安装将由它驱动,遵循以下优先顺序:
¥This command installs a package and any packages that it depends on. If the package has a package-lock, or an npm shrinkwrap file, or a yarn lock file, the installation of dependencies will be driven by that, respecting the following order of precedence:
-
npm-shrinkwrap.json
-
package-lock.json
-
yarn.lock
见 package-lock.json 和 npm shrinkwrap
。
¥See package-lock.json and npm shrinkwrap
.
一个 package
是:
¥A package
is:
-
a) 包含由
package.json
文件描述的程序的文件夹¥a) a folder containing a program described by a
package.json
file -
b) 一个 gzipped tarball,包含 (a)
¥b) a gzipped tarball containing (a)
-
c) 解析为 (b) 的 url
¥c) a url that resolves to (b)
-
d) 在注册表上发布的
<name>@<version>
(参见registry
),带有 (c)¥d) a
<name>@<version>
that is published on the registry (seeregistry
) with (c) -
e) 指向 (d) 的
<name>@<tag>
(见npm dist-tag
)¥e) a
<name>@<tag>
(seenpm dist-tag
) that points to (d) -
f) 具有满足 (e) 的 "latest" 标签的
<name>
¥f) a
<name>
that has a "latest" tag satisfying (e) -
g) 解决为 (a) 的
<git remote url>
¥g) a
<git remote url>
that resolves to (a)
即使你从不发布你的包,如果你只是想写一个 node 程序(a),你仍然可以获得使用 npm 的很多好处,也许你还想在打包后能够轻松地安装它成一个 tarball (b)。
¥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).
-
npm install
(在包目录中,无参数):¥
npm install
(in a package directory, no arguments):将依赖安装到本地
node_modules
文件夹。¥Install the dependencies to the local
node_modules
folder.在全局模式下(即,将
-g
或--global
附加到命令中),它将当前包上下文(即当前工作目录)安装为全局包。¥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.默认情况下,
npm install
将安装package.json
中列为依赖的所有模块。¥By default,
npm install
will install all modules listed as dependencies inpackage.json
.使用
--production
标志(或者当NODE_ENV
环境变量设置为production
时),npm 将不会安装devDependencies
中列出的模块。当NODE_ENV
环境变量设置为production
时,要安装dependencies
和devDependencies
中列出的所有模块,你可以使用--production=false
。¥With the
--production
flag (or when theNODE_ENV
environment variable is set toproduction
), npm will not install modules listed indevDependencies
. To install all modules listed in bothdependencies
anddevDependencies
whenNODE_ENV
environment variable is set toproduction
, you can use--production=false
.注意:在向项目添加依赖时,
--production
标志没有特殊含义。¥NOTE: The
--production
flag has no particular meaning when adding a dependency to a project. -
npm install <folder>
:如果
<folder>
位于项目的根目录中,它的依赖将被安装,并且可能会像其他类型的依赖一样被提升到顶层node_modules
。如果<folder>
位于项目根目录之外,npm 不会在目录<folder>
中安装包依赖,但会创建到<folder>
的符号链接。¥If
<folder>
sits inside the root of your project, its dependencies will be installed and may be hoisted to the top-levelnode_modules
as they would for other types of dependencies. If<folder>
sits outside the root of your project, npm will not install the package dependencies in the directory<folder>
, but it will create a symlink to<folder>
.注意:如果你想从注册表安装目录的内容(如包)而不是创建链接,则需要使用
--install-links
选项。¥NOTE: If you want to install the content of a directory like a package from the registry instead of creating a link, you would need to use the
--install-links
option.示例:
¥Example:
npm install ../../other-package --install-linksnpm install ./sub-package -
npm install <tarball file>
: