[英]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 中拥有一个虚拟存储库,其中包含两个存储库:
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.