LoginSignup
23
24

More than 5 years have passed since last update.

bowerべんりっぽい

Last updated at Posted at 2013-04-15

噂には聞いてたけど。1度ひととおりの機能確認してみた。
クライアントサイドのライブラリをインストール・管理できるツール。

install

npm -g install bower


jqueryをインストール

bower install jquery

componentsディレクトリができて、jqueryが入ってる。
名前には出てないけど最新版が来てる(っぽい)。

ちなみにjquery公式ではなく、
https://github.com/components/jquery からとってくる。
bowerにcomponentとして登録されているものをインストールという形。

jqueryをインストールして、覚えておく

bower install jquery --save

component.jsonができて、jqueryをdependenciesとして覚えててくれる。

sample-project/component.json
{
  "name": "sample-project",
  "version": "0.0.0",
  "dependencies": {
    "jquery": "~1.9.1"
  }
}

ちなみに--save-devもある。

覚えておいたdependenciesは、引数なしでbower installすると、
勝手に全部インストールしてくれる。

これによってたとえば、ライブラリはgitのレポジトリに含めず、
component.jsonだけ入れておき、インストール時にbower installという使い方ができる。

カスタマイズ

インストール先のディレクトリは、デフォルトではcomponents。
でもこの名前はちょっと使いづらい! って気もするので
変えたい。

.bowerrcをつくって、directoryを記述すると変更できる。

sample-project/.bowerrc
{
  directory: "js/lib"
}

こんな感じのをすぐ打てるようにしとくとよさそう。
(本当はbowerのサブコマンドで.bowerrcを編集できるようにしてほしいけど。。。)

echo '{ "directory": "js/lib" }' > .bowerrc

まとめ

思った以上にnpmと同じ使い方ができるので素敵。
覚えるコストもほぼなさそう。

bower componentを公開するのも今度やりたい。
たぶんすぐできそう。

23
24
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
23
24