【问题标题】:how to isolate dependencies in bower如何隔离凉亭中的依赖关系
【发布时间】:2014-07-02 09:54:39
【问题描述】:

我记得在某处读过,在 bower 中您可以将包安装为子树,这意味着一个项目可以使用同一库的多个版本。每个版本的库都充当需要不同版本的其他库的依赖项。

作为一个例子..假设我正在开发一个同时使用angular-google-maps 和ui-slider..的项目。 angular-google-maps 至少需要angular 1.2.18+ 和ui-slider 需要angular 1.0.8 ` 我希望得到这样的东西(即凉亭列表的输出):

├── angular#1.2.18
├─┬ angular-google-maps#1.1.2 extraneous (latest is 1.1.6)
│ ├── angular#1.2.18
│ └── ..
├─┬ angular-ui-slider#0.0.2
│ ├── angular#1.0.8
│ ├── ..

相反,当我尝试在我现有的项目上安装 ui-slider 时,已经使用了angular 1.2.18,我得到了这个提示:

Unable to find a suitable version for angular, please choose one:
    1) angular#~1.0.x which resolved to 1.0.8 and is required by angular-ui-slider#0.0.2 
    2) angular#1.2.5 which resolved to 1.2.5 and is required by angular-sanitize#1.2.5 
    3) angular#1.2.18 which resolved to 1.2.18 and is required by angular-brunch-seed 
    4) angular#>=1 which resolved to 1.2.19 and is required by angular-bootstrap#0.5.0 
    5) angular#~1.2.0 which resolved to 1.2.19 and is required by angular-masonry#0.8.1 
    6) angular#1.2.x which resolved to 1.2.19 and is required by angular-google-maps#1.1.2 
    7) angular#1.2.19 which resolved to 1.2.19 and is required by angular-animate#1.2.19 
    8) angular#* which resolved to 1.2.19 and is required by restangular#1.4.0

Prefix the choice with ! to persist it to bower.json

我自然会选择一个拿到1.0.8:

[?] Answer: 1
bower angular#~1.0.x                    install angular#1.0.8
bower angular-ui-slider#~0.0.2          install angular-ui-slider#0.0.2

但是,当我运行 bower list 时,我得到:

├── angular#1.0.8 incompatible with 1.2.18 (1.2.18 available, latest is 1.3.0-build.2867+sha.f07af61)
├─┬ angular-animate#1.2.19 (latest is 1.3.0-build.2867+sha.f07af61)
│ └── angular#1.0.8 incompatible with 1.2.19 (1.2.19 available, latest is 1.3.0-build.2867+sha.f07af61)
├─┬ angular-bootstrap#0.5.0 (latest is 0.11.0)
│ └── angular#1.0.8 (1.3.0-build.2867+sha.f07af61 available)
├─┬ angular-cookies#1.2.5 (latest is 1.3.0-build.2867+sha.f07af61)
│ └── angular#1.0.8 incompatible with 1.2.5 (1.2.5 available, latest is 1.3.0-build.2867+sha.f07af61)
├─┬ angular-google-maps#1.1.2 extraneous (latest is 1.1.6)
│ ├── angular#1.0.8 incompatible with 1.2.x (1.2.19 available, latest is 1.3.0-
├─┬ angular-ui-slider#0.0.2
│ ├── angular#1.0.8 (latest is 1.3.0-build.2867+sha.f07af61)
..

问题:为什么 bower 将 angular 1.0.8 设为 default 角度,而将其用于 all 我的其他库.. 而不是保留 angular 1.2.18 并仅使用 @ 987654336@ 为angular-ui-slider?

【问题讨论】:

标签: javascript jquery angularjs bower bower-install


【解决方案1】:

您不能同时运行两个版本的 Angular。所以 Bower 要求您选择要安装的那个。在这里您选择 1,因此无论兼容性如何,它都会为您的所有软件包安装 angular 1.0.8 依赖项。
这是设计意图的行为。

【讨论】:

  • 那么这是特定于 Angular 库还是适用于所有库?
  • bower 中的所有包都是一样的。例如:如果您需要 angular-ui 和 angular-animate。它们都需要 angular 作为依赖项,因此 bower 将为这些软件包自动安装它。但是 bower 很聪明地问你,当包需要来自同一个库的不同版本时,你想要什么版本。告诉你 angular-ui 需要这个版本的 angular 而 angular-animate 需要另一个。您可以在 /bower_components/name-of-package/bower.json 中查看每个包的依赖关系
  • 我想我做到了。我的意思是它对于 jQuery 或任何其他包都是一样的。在 /bower_components/ 中仅下载每个库的一个版本,因为您无法并行加载和使用同一库的不同版本。这不是特定于角度的。
猜你喜欢
  • 1970-01-01
  • 2014-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多