Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 996
Kamil W Avatar asked Oct 18 '17 10:10

Kamil W


People also ask

How npm install specific dependencies?

Summary. For npm install specific version, use npm install [package-name]@[version-number]. Use npm view [package-name] version to know the specific latest version of a package available on the npm registry. Use npm list [package-name] to know the specific latest version of an installed package.

How do I get NPM package dependencies?

To specify the packages your project depends on, you must list them as "dependencies" or "devDependencies" in your package's package. json file. When you (or another user) run npm install , npm will download dependencies and devDependencies that are listed in package.


1 Answers

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

like image 56
Srini Karthikeyan Avatar answered Sep 21 '22 08:09

Srini Karthikeyan