I see instructions to install a package with either
我看到安装包的说明
npm install <package_name>
or
要么
npm install <package_name> --save
or
要么
npm install <package_name> -- save dev-save
What is the difference between these options?
这些选项有什么区别?
2 个解决方案
#1
23
npm install takes 3 exclusive, optional flags which save or update the package version in your main package.json:
npm install需要3个独占的可选标志,用于保存或更新主package.json中的软件包版本:
-S, --save: Package will appear in your dependencies.
-S, - save:包将出现在您的依赖项中。
-D, --save-dev: Package will appear in your devDependencies.
-D, - save-dev:包将出现在devDependencies中。
-O, --save-optional: Package will appear in your optionalDependencies.
-O, - save-optional:包将出现在optionalDependencies中。
When using any of the above options to save dependencies to your package.json, there is an additional, optional flag:
当使用上述任何选项来保存对package.json的依赖关系时,还有一个额外的可选标志:
-E, --save-exact: Saved dependencies will be configured with an exact version rather than using npm's default semver range operator. Further, if you have an npm-shrinkwrap.json then it will be updated as well.
-E, - save-exact:保存的依赖项将使用精确版本配置,而不是使用npm的默认semver范围运算符。此外,如果您有一个npm-shrinkwrap.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.
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 --save 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 --save-exact
npm install sax --save 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 --save-exact
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.
注意:如果当前工作目录中存在名为
(from official docs) https://docs.npmjs.com/cli/install
(来自官方文档)https://docs.npmjs.com/cli/install
#2
15
npm install <package_name>
without an option, just installs the package but does not update the dependencies as listed in your package.json.
npm install
npm install <package_name> --save
installs the package and updates the dependencies in your package.json.
npm install
npm install <package_name> ---save-dev
updates the devDependencies
in your package. These are only used for local testing and development.
npm install
You can read more at https://docs.npmjs.com/getting-started/using-a-package.json.
您可以在https://docs.npmjs.com/getting-started/using-a-package.json上阅读更多内容。
#1
23
npm install takes 3 exclusive, optional flags which save or update the package version in your main package.json:
npm install需要3个独占的可选标志,用于保存或更新主package.json中的软件包版本:
-S, --save: Package will appear in your dependencies.
-S, - save:包将出现在您的依赖项中。
-D, --save-dev: Package will appear in your devDependencies.
-D, - save-dev:包将出现在devDependencies中。
-O, --save-optional: Package will appear in your optionalDependencies.
-O, - save-optional:包将出现在optionalDependencies中。
When using any of the above options to save dependencies to your package.json, there is an additional, optional flag:
当使用上述任何选项来保存对package.json的依赖关系时,还有一个额外的可选标志:
-E, --save-exact: Saved dependencies will be configured with an exact version rather than using npm's default semver range operator. Further, if you have an npm-shrinkwrap.json then it will be updated as well.
-E, - save-exact:保存的依赖项将使用精确版本配置,而不是使用npm的默认semver范围运算符。此外,如果您有一个npm-shrinkwrap.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.
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 --save 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 --save-exact
npm install sax --save 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 --save-exact
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.
注意:如果当前工作目录中存在名为
(from official docs) https://docs.npmjs.com/cli/install
(来自官方文档)https://docs.npmjs.com/cli/install
#2
15
npm install <package_name>
without an option, just installs the package but does not update the dependencies as listed in your package.json.
npm install
npm install <package_name> --save
installs the package and updates the dependencies in your package.json.
npm install
npm install <package_name> ---save-dev
updates the devDependencies
in your package. These are only used for local testing and development.
npm install
You can read more at https://docs.npmjs.com/getting-started/using-a-package.json.
您可以在https://docs.npmjs.com/getting-started/using-a-package.json上阅读更多内容。