Help us understand the problem. What is going on with this article?

grunt-bower-taskのlayoutが気に入らなかったので作った

More than 5 years have passed since last update.

bowerを最近ようやく使い始めて、grunt-bower-taskで良い感じにtargetDirに吐き出すようにしたかったんですが、
デフォルトのlayoutはやたらディレクトリが深くなったり、
きちんとbower.jsonでmainを指定しているのとそうでないのとで構造が違ってくるとか、
もうなんか嫌だなあと思ったのでサクッと自前でlayout作ってみた。

Gruntfile.js
var path = require('path');
bower: {
    options: {
        targetDir: 'js/lib',
        layout: function(type, component) {
            var makeDir = false;
            if(makeDir) {
                if(type === 'css') {
                    return path.join(component, type);
                } else {
                    return path.join(component);
                }
            }
        }
    }
}

targetDirには吐き出したい先のディレクトリ、 makeDirはコンポーネントごとにディレクトリ分けるかどうかbooleanで記述します。

上の例ではjs/lib直下にライブラリのファイルが吐き出されるようになります。

あとはbower.jsonで良い感じにexportsOverrideを書いておけば(例えば本当に使うファイルだけ指定しておく)、きっと良い感じに吐き出してくれます。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした