覆盖bower.json文件中的依赖项

时间:2015-07-15 21:45:50

标签: bower

我试图覆盖我在聚合物组件中包含的其中一个包的依赖关系,并且似乎无法使其工作。

bower.json文件如下所示:

"dependencies": {
"polymer": "Polymer/polymer#^1.0.0",
"paper-material": "PolymerElements/paper-material#^1.0.0",
"paper-toolbar" : "PolymerElements/paper-toolbar#^1.0.0",
"paper-styles": "PolymerElements/paper-styles#^1.0.0",
"iron-icon": "polymerelements/iron-icon#^1.0.0",
"iron-icons": "polymerelements/iron-icons#^1.0.0"
},

"overrides": {
  "paper-styles": {
    "dependencies": {
     "iron-flex-layout": "PolymerElements/iron-flex-layout#^1.0.0",
     "font-roboto": "PolymerElements/font-roboto-local#^1.0.1",
     "polymer": "Polymer/polymer#^1.0.0"
   }
 }
},
"devDependencies": {
  "iron-component-page": "PolymerElements/iron-component-page#^1.0.0",
  "web-component-tester": "*"

}

基本上我试图用font-roboto-local包替换font-roboto包。谁能看到我在这里做错了什么?除非我错误地解释文档,否则这应该有效。

1 个答案:

答案 0 :(得分:3)

Bower使用平面依赖树;因此您无需通过overrides更改纸张样式的依赖关系,您可以直接在bower.json中执行此操作:

"dependencies": {
  "paper-styles": "PolymerElements/paper-styles#^1.0.0",
  "font-roboto": "PolymerElements/font-roboto-local#^1.0.0"
}

编辑:起初这对我有用,但随后bower突然切换回使用font-roboto。这似乎是因为paper-styles需要^ 1.0.1,但font-roboto-local仅在1.0.0中可用。这意味着对于能够满足版本标准的bower比要安装的包更重要。

我可以通过将版本设置为1.0.0而不使用^:

来解决此问题
"dependencies": {
  "paper-styles": "PolymerElements/paper-styles#^1.0.0",
  "font-roboto": "PolymerElements/font-roboto-local#1.0.0"
},
"resolutions": {
  "font-roboto": "1.0.0"
}

缺点是您现在必须手动更新版本,但至少它可以正常工作。