创建和发布组织范围的包

作为组织成员,你可以在组织范围内创建和发布公共和私有包。

¥As an organization member, you can create and publish public and private packages within the organization's scope.

创建组织范围的包

¥Creating an organization scoped package

  1. 在命令行上,使用你要创建的包的名称创建一个目录。

    ¥On the command line, make a directory with the name of the package you would like to create.

    mkdir /path/to/package/directory
  2. 导航到新创建的包目录。

    ¥Navigate to the newly-created package directory.

  3. 要创建组织范围的包,请在命令行上运行:

    ¥To create an organization scoped package, on the command line, run:

    npm init --scope=<your_org_name>
  4. 要验证包是否使用你的组织范围,请在文本编辑器中打开包的 package.json 文件并检查名称是否为 @your_org_name/<pkg_name>,将 your_org_name 替换为你的组织名称。

    ¥To verify the package is using your organization scope, in a text editor, open the package's package.json file and check that the name is @your_org_name/<pkg_name>, replacing your_org_name with the name of your organization.

发布私有组织范围的包

¥Publishing a private organization scoped package

默认情况下,npm publish 会将范围包发布为私有。

¥By default, npm publish will publish a scoped package as private.

默认情况下,任何范围包都作为私有发布。但是,如果你的组织没有 Private Packages 功能,除非你通过 access 标志,否则 npm publish 将失败。

¥By default, any scoped package is published as private. However, if you have an organization that does not have the Private Packages feature, npm publish will fail unless you pass the access flag.

  1. 在命令行上,导航到包目录。

    ¥On the command line, navigate to the package directory.

  2. 运行 npm publish

    ¥Run npm publish.

私有包会在 npm 网站上的包名下方显示 private

¥Private packages will say private below the package name on the npm website.

Screenshot of a private npm Teams package

发布公共组织范围的包

¥Publishing a public organization scoped package

要将组织范围的包发布为公共,请使用 npm publish --access public

¥To publish an organization scoped package as public, use npm publish --access public.

  1. 在命令行上,导航到包目录。

    ¥On the command line, navigate to the package directory.

  2. 运行 npm publish --access public

    ¥Run npm publish --access public.

公共包会在 npm 网站上的包名下方显示 public

¥Public packages will say public below the package name on the npm website.

Screenshot of a public npm Teams package
npm 中文网 - 粤ICP备13048890号