See Details
目录
注意:你必须使用 npm 版本 2 或更高版本才能使用范围。要升级到最新版本的 npm,请在命令行上运行 npm install npm@latest -g
¥Note: You must be using npm version 2 or greater to use scopes. To upgrade to the latest version of npm, on the command line, run npm install npm@latest -g
当你注册 npm 用户账户或创建组织时,你将获得与你的用户或组织名称匹配的范围。你可以将此范围用作相关包的命名空间。
¥When you sign up for an npm user account or create an organization, you are granted a scope that matches your user or organization name. You can use this scope as a namespace for related packages.
范围允许你创建与其他用户或组织创建的包同名的包,而不会发生冲突。
¥A scope allows you to create a package with the same name as a package created by another user or organization without conflict.
当在 package.json
文件中列为依赖时,范围包的前面是它们的作用域名称。范围名称是 @
和斜杠之间的所有内容:
¥When listed as a dependent in a package.json
file, scoped packages are preceded by their scope name. The scope name is everything between the @
and the slash:
-
"npm" 范围:
¥**"npm" scope:**
@npm/package-name
-
"npmcorp" 范围:
¥**"npmcorp" scope:**
@npmcorp/package-name
要创建和发布公共范围的包,请参阅“创建和发布范围公共包”。
¥To create and publish public scoped packages, see "Creating and publishing scoped public packages".
要创建和发布私有范围的包,请参阅“创建和发布私有包”。
¥To create and publish private scoped packages, see "Creating and publishing private packages".
范围和包可见性
¥Scopes and package visibility
-
无范围的包总是公开的。
¥Unscoped packages are always public.
-
私有包 始终是有范围的。
¥Private packages are always scoped.
-
默认情况下,Scoped 包是私有的;发布时必须传递命令行标志才能公开它们。
¥Scoped packages are private by default; you must pass a command-line flag when publishing to make them public.
有关包范围和可见性的更多信息,请参阅“包的范围、访问级别和可见性”。
¥For more information on package scope and visibility, see "Package scope, access level, and visibility".