简体   繁体   English

私有和公共NPM软件包以单个命令安装

[英]Private and Public NPM Package Install in Single Command

I have a few npm package listed in package.json file , some are public and some are private. 我在package.json文件中列出了一些npm软件包,有些是公共的,有些是私有的。 I want to install both types of packages in single command by using npm install . 我想使用npm install在单个命令中安装两种类型的软件包。

If npm registry set on global, private package shows 404 , so how to achieve this by single command.I want Both types of package install on node_modules. 如果在全局NPM注册表上设置私有包显示404 ,那么如何通过单个命令实现此目的。我想两种类型的包都安装在node_modules上。

The faster solution is what @hugomarisco suggested in the comment section. 更快的解决方案是@hugomarisco在评论部分中建议的。 I'll assume your private package is in any registry (A) and the remainings are fetched from npmjs (B). 我假设您的私人软件包在任何注册表中(A),其余的则从npmjs(B)中获取。

To make it more clear, you can use verdaccio and set up your multiples registries as uplinks as is visualized here. 为了更加清楚,您可以使用verdaccio并将多重注册表设置为上行链路,如此处所示。

在此处输入图片说明

Your uplink configuration might look like this, 您的上行链路配置可能如下所示,

uplinks:
  npmjsA:
   url: https://registry.npmjs.org/
  registryB:
    url: http://mirror.local.net/

and then just define the package access to each remote by patterns 然后只需按模式定义程序包对每个遥控器的访问权限

packages:
  'my-private-*':
     access: $authenticated
     publish: $authenticated  
     proxy: registryB    
  '**':
     access: all
     publish: $authenticated
     proxy: npmjs  

In such way, you can access your private packages safely while verdaccio fetch for you those belong any public registry as npmjs. 在这种方式,你可以安全地访问您的私人包而verdaccio获取你那些属于任何公共登记处为npmjs。

In your terminal just do 在您的终端中做

npm set registry http://localhost:4873 
npm install

and you are set. 并且您被设置。 I hope that helps. 希望对您有所帮助。

npm --usercofig=./.npmrccorp i : This will install the modules as mentioned in package.json while considering the configuration file supplied by the --userconfig argument. npm --usercofig=./.npmrccorp i :这将安装package.json提到的模块,同时考虑--userconfig参数提供的配置文件。 The last i and install are interchangeable. 最后的iinstall可以互换。 This can be rewritten as npm --usercofig=./.npmrccorp install also 也可以将其重写为npm --usercofig=./.npmrccorp install

To install both private and public packages with single npm --usercofig=./.npmrccorp i command you need to maintain both the dependencies in package.json dependencies node and then there should be a .npmrccorp file containing your authentication token as follows: 要安装私人和公共包单npm --usercofig=./.npmrccorp i命令你需要保持这两个dependenciespackage.json依赖节点,那么就应该包含您的身份验证令牌如下一个.npmrccorp文件:

package.json : package.json

{
  "dependencies": {
    "@org/package1": "^1.0.14",
    "@org/package2": "^1.0.0",
    "public package1": "^1.5.0",
    "public package1": "^2.117.0",
   }
}

.npmrccorp .npmrccorp

//registry.npmjs.org/:_authToken=a*******-****-****-****-***********1 (32 bit authentication token)

After did all experiment, i up all my private package to server as a scoped package. 经过所有实验后,我将所有私有软件包作为有作用域的软件包上传到服务器。 like as @private/jsonwrite , @private is my scoped name. 像如@private/jsonwrite@private就是我的作用域的名字。 then i write below config in .npmrc 然后我在.npmrc中的配置下面写

@private:registry=https://npmjs.my-private-repo.net

then just run npm install , it works both on remote and global package. 然后只需运行npm install ,它就可以在远程和全局软件包中使用。 Which is scoped package download from .npmrc given link and rest of others from global npm. 这是从.npmrc给定链接下载的范围软件包,以及从全局npm下载的其他软件包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM