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

时间:2023-01-19 18:15:28

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 e.g.

我正在寻找使用插入符号或tidle来声明依赖关系的方法,例如

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

Thank you in advance.

先谢谢你。

1 个解决方案

#1


4  

I recommend you to have a virtual repository in your Artifactory with two repos:

我建议你在Artifactory中有一个带有两个repos的虚拟存储库:

  1. Remote repo with the external repo or public registry. Probably you have this URL in your registry.
  2. 具有外部仓库或公共注册表的远程仓库。您的注册表中可能包含此URL。
  3. Local NPM repo (your actual local repo).
  4. 本地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. 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:

更多信息:

#1


4  

I recommend you to have a virtual repository in your Artifactory with two repos:

我建议你在Artifactory中有一个带有两个repos的虚拟存储库:

  1. Remote repo with the external repo or public registry. Probably you have this URL in your registry.
  2. 具有外部仓库或公共注册表的远程仓库。您的注册表中可能包含此URL。
  3. Local NPM repo (your actual local repo).
  4. 本地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. 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:

更多信息: