How to have npm dependencies from different registries in the package.json?
To have dependencies from different registries referred in same package.json, npm recommends to use 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 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
Refer: https://docs.npmjs.com/cli/v6/using-npm/scope
I recommend you to have a virtual repository in your Artifactory with two repos:
- Remote repo with the external repo or public registry. Probably you have this URL in your registry.
- 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:
- how to setting up artifactory for use with node js artifacts?
- Npm Registry with Jfrog Artifactory