简体   繁体   English

如何在 package.json 中拥有来自不同注册表的 npm 依赖项?

[英]How to have npm dependencies from different registries in the package.json?

In my package.json file I have declared dependencies which one from public registry and second from private registry (Artifactory in this case).在我的 package.json 文件中,我声明了依赖项,其中一个来自公共注册表,第二个来自私有注册表(在这种情况下为 Artifactory)。

"dependencies": {
        "vue": "^2.4.4", //public registry
        "ce-ui": "http://myartifactory.com/artifactory/npm-local/ce-ui/-/ce-ui-0.0.2.tgz"
      }

I'm looking for way to declare dependencies using caret or tidle eg我正在寻找使用 caret 或 tidle 声明依赖项的方法,例如

 "dependencies": {
    "vue": "^2.4.4",
    "ce-ui": "^0.0.2"
  }

Thank you in advance.提前谢谢你。

To have dependencies from different registries referred in same package.json, npm recommends to use scope要在同一个 package.json 中引用来自不同注册表的依赖项,npm 建议使用 scope

Scoped packages will look like作用域包看起来像

"dependencies": {
  "@myorg/mypackage": "^1.3.0"
}

You can associate a scope with a registry using npm config:您可以使用 npm config 将范围与注册表关联:

npm config set @myorg:registry http://reg.example.com

Once a scope is associated with a registry, any npm install for a package with that scope will request packages from that registry instead of default registry https://registry.npmjs.org一旦范围与注册表相关联,具有该范围的包的任何 npm 安装都将从该注册表而不是默认注册表https://registry.npmjs.org请求包

Refer: https://docs.npmjs.com/cli/v6/using-npm/scope参考: https : //docs.npmjs.com/cli/v6/using-npm/scope

I recommend you to have a virtual repository in your Artifactory with two repos:我建议您在 Artifactory 中拥有一个虚拟存储库,其中包含两个存储库:

  1. Remote repo with the external repo or public registry.带有外部存储库或公共注册表的远程存储库。 Probably you have this URL in your registry.您的注册表中可能有此 URL。
  2. Local NPM repo (your actual local repo).本地 NPM 存储库(您的实际本地存储库)。

Then:然后:

  • Replacing the default registry with your new local repository with this command:使用以下命令将默认注册表替换为新的本地存储库:

     npm config set registry http://<ARTIFACTORY_SERVER_DOMAIN>:8081/artifactory/api/npm/your-npm-virtual-repo-name
  • Deploy your packages to Artifactory.将您的包部署到 Artifactory。 The first time you can upload the artifacts to artifactory manually or using this command in every project:第一次您可以手动将工件上传到 artifactory 或在每个项目中使用此命令:

     npm publish --registry http://<ARTIFACTORY_SERVER_DOMAIN>:8081/artifactory/api/npm/your-virtual-repo-name
  • Remove links in your package.json and replace with only the dependency name and version like:删除 package.json 中的链接并仅替换为依赖项名称和版本,例如:

     "dependencies": { "vue": "^2.4.4", "ce-ui": "^0.0.2" }

More info here:更多信息在这里:

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

相关问题 有没有一种方法可以将package.json文件中的依赖项安装到其他目​​录中? - Is there a way to install dependencies from a package.json file into a different directory? 为什么 package-lock.json 与 package.json 有不同的列出的依赖关系? - Why does package-lock.json have different listed dependencies to package.json? 为什么package.json和npm info之间的依赖库版本不同 - Why dependencies library version is different between package.json and npm info npm 安装无法从每个依赖项的依赖项中找到 package.json - npm install cannot find package.json from dependencies of each dependency 从package.json安装依赖项时出错 - error installing dependencies from package.json npm init之后,package.json文件中没有依赖项 - No dependencies in package.json file, after npm init npm install --global(对于 package.json 的所有依赖项) - npm install --global (for all dependencies on package.json) 如何将我通过npm安装的所有依赖项保存到我的package.json文件中? - How do I save all the dependencies I install through npm into my package.json file? 使用jq从package.json中提取有关依赖项的信息 - Using jq to extract information about dependencies from package.json 从package.json配置npm cli标志 - Configure npm cli flags from package.json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM