使用组织设置配置 npm 客户端

作为组织成员,你可以将 npm 客户端配置为:

As an organization member, you can configure your npm client to:

  • 使你在本地创建的单个包或所有新包都使用你组织的范围

    make a single package or all new packages you create locally use your organization's scope

  • 使你在本地创建的单个包或所有新包具有默认的公共可见性

    make a single package or all new packages you create locally have default public visibility

在配置你的 npm 客户端之前,你必须 安装 npm

Before configuring your npm client, you must install npm.

配置你的 npm 客户端来使用你组织的范围

Configuring your npm client to use your organization's scope

如果你将经常发布具有组织范围的包,则可以将组织范围添加到全局 .npmrc 配置文件中。

If you will be publishing packages with your organization's scope often, you can add your organization's scope to your global .npmrc configuration file.

为所有新的包设置组织范围

Setting your organization scope for all new packages

注意:使用以下步骤设置组织范围只会设置新包的范围;对于现有包,你需要更新 package.json 中的 name 字段。

Note: Setting the organization scope using the steps below will only set the scope for new packages; for existing packages, you will need to update the name field in package.json.

在命令行上,运行以下命令,将 <org-name> 替换为你的组织名称:

On the command line, run the following command, replacing <org-name> with the name of your organization:

npm config set scope <org-name> --global

对于你不想使用组织范围发布的包,你必须手动编辑包的 package.json 以从 name 字段中删除组织范围。

For packages you do not want to publish with your organization's scope, you must manually edit the package's package.json to remove the organization scope from the name field.

为单个包设置组织范围

Setting your organization scope for a single package

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

    On the command line, navigate to the package directory.

    cd /path/to/package
  2. 运行以下命令,将 <org-name> 替换为你的组织名称:

    Run the following command, replacing <org-name> with the name of your organization:

    npm config set scope <org-name>

将默认包可见性更改为公共

Changing default package visibility to public

默认情况下,使用 npm publish 发布范围包会将包发布为私有。如果你是免费组织计划的组织成员,或者是付费组织计划但希望将范围包发布为公共,则必须传递 --access public 标志:

By default, publishing a scoped package with npm publish will publish the package as private. If you are a member of an organization on the free organization plan, or are on the paid organization plan but want to publish a scoped package as public, you must pass the --access public flag:

npm publish --access public

将单个包的包可见性设置为公开

Setting package visibility to public for a single package

你可以将单个包设置为将 --access public 传递给你为该包触发的每个 npm publish 命令。

You can set a single package to pass --access public to every npm publish command that you issue for that package.

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

    On the command line, navigate to the package directory.

    cd /path/to/package
  2. 运行以下命令:

    Run the following command:

    npm config set access public

将所有包的包可见性设置为公开

Setting package visibility to public for all packages

你可以将所有包设置为将 --access public 传递给你为该包触发的每个 npm publish 命令。

You can set all packages to pass --access public to every npm publish command that you issue for that package.

警告:在全局 .npmrc 中设置对 public 的包访问权限将影响你创建的所有包,包括你个人账户范围内的包以及组织范围内的包。

Warning: Setting packages access to public in your global .npmrc will affect all packages you create, including packages in your personal account scope, as well as packages scoped to your organization.

在命令行上,运行以下命令:

On the command line, run the following command:

npm config set access public --global
npm 中文网 - 粤ICP备13048890号