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

Kamil W picture Kamil W · Oct 18, 2017 · Viewed 7.9k times · Source

In my package.json file I have declared dependencies which one from public registry and second from private registry (Artifactory in this case).

"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.

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

Thank you in advance.

Answer

Javier C. picture Javier C. · Oct 18, 2017

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

  1. Remote repo with the external repo or public registry. Probably you have this URL in your registry.
  2. Local NPM repo (your actual local repo).

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:

    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:

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

More info here: