LoginSignup
40
40

More than 5 years have passed since last update.

[Bower] bower_components ディレクトリはgitで管理すべきか問題

Last updated at Posted at 2014-01-27

bowergemcomposerと違って*.lockファイルがありません。

bowerを利用した際に実ファイルがbower_componentsディレクトリに保存されますが、

gitで管理すべきか?という話。

bower_components は管理しなくても良い

結論を言うと 管理しなくてよい です。

しかし実際bowerを使っていると、たまに依存が解決できない時があります。

Unable to find a suitable version for jquery, please choose one:
    1) jquery#>=1.8.0 <2.1.0 which resolved to 2.0.3 and has bootstrap#2.3.2 as dependants
    2) jquery#>=1.7 which resolved to 2.1.0 and has bootstrap-select#1.3.7 as dependants
    3) jquery#>=1.9.0 which resolved to 2.1.0 and has bootstrap-switch#2.0.1 as dependants

その際にはbowerがどれを採用するかを聞いてきて、人間が指定して依存を解決します。

しかしこれだけでは、bower_componentsディレクトリをバージョン管理していない場合に同じことが起こります。

この現象に出くわすとbower_componentsをバージョン管理したくなりますが、必要ありませんでした。

resolutions

bower.jsonresolutionsにパッケージのバージョンをあらかじめ書いておく事で、コンフリクトを起こさずに済みます。

bower.json
{
    "resolutions": {
        "jquery": "1.8.3"
    }
}

バージョンを指定するだけなので、composer.lockのようなgitのコミットハッシュより安心感は無いですが、依存を毎回手動で解決する必要はなくなります。

どうしてもこのコミットじゃなければだめだ!という場合以外は、resoltionsを指定する事で解決できます。

bowerが依存解決を聞いてきた時に、!を前に付けて返事をすると自動的にbower.jsonが更新されます。
例: !2

bowerの返事をよく読んでなかった&調べてもあんま出ないのでモヤッとしてました。笑

40
40
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
40
40