基于目录切换 npm 注册表 [英] switching npm registry based on directory
问题描述
我最近开始为 node 开发.我工作的公司有一个内部 npm 注册表.我想知道如何根据我的开发位置使用不同的注册表设置.为了说明,我有一个如下所示的目录结构:
<代码>~/代码||-- 我的项目||||-- 项目 1||-- 项目 2||-- 我的公司||--项目1|--项目二
当我在我的项目"中的一个项目中进行开发时,我希望 npm 注册表指向 https://registry.npmjs.org(默认注册表).但是,当我在我的公司"中的一个项目中进行开发时,我希望 npm 注册表指向公司特定的注册表.现在,我天真的方法是使用npm config set registry
更新注册表.
使用私有 npm 注册表有两种不同的用例:
安装:使用
--reg
或--registry
标志:npm install mypackage --reg http://myreg.npmjitsu.com
发布:您也可以使用
--reg
或--registry
,但我强烈建议您使用publishConfig
在您的package.json
文件中设置(参见:npm 文档)<代码>{发布配置":{注册表":http://myreg.npmjitsu.com"}}
这可以防止开发人员通过忘记
--registry
标志 而意外地将私有模块发布到公共注册中心
因此,将 publishConfig
添加到所有 package.json
中,以便您的公司在从其私有 npm 安装时使用 --registry
.>
I have recently started developing for node. The company that I work for has an internal npm registry. I want to know how to use different registry settings depending upon where I am developing. To illustrate, I have a directory structure like shown below:
~/Code
|
| -- My Projects
| |
| | -- Proj 1
| | -- Proj 2
|
|-- My Company
|
|--Proj 1
|--Proj 2
When I am developing in one of the projects in 'My Project', I would like the npm registry to point to https://registry.npmjs.org (the default registry). But when I am developing in one of the projects in 'My Company', I want npm registry to point to the company specific registry. Right now, my naive method is to use
npm config set registry
to update the registry.
There are two distinct use cases for using your private npm registry:
Installing: use the
--reg
or--registry
flag:npm install mypackage --reg http://myreg.npmjitsu.com
Publishing: you can also use
--reg
or--registry
, but I would highly recommend that you use thepublishConfig
setting in yourpackage.json
file (See: the npm documentation){ "publishConfig": { "registry": "http://myreg.npmjitsu.com" } }
This prevents developers from accidentally publishing private modules to the public registry by forgetting the
--registry
flag
So add publishConfig
to all of the package.json
for your Company use --registry
when installing from their private npm.
这篇关于基于目录切换 npm 注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!