LoginSignup
15
15

More than 5 years have passed since last update.

gulp-webpackで複数のファイルをコンパイルするときに注意する点のメモ

Last updated at Posted at 2015-02-23

問題

  • gulp-webpackでは、webpackを内部で呼び出している。
  • その際、copyせずにentryやoutputにデータを入れてstream対応している。
  • 公式ドキュメントのようにwebpack(require("webpack.config"))するとrequireのキャッシュにより、同じオブジェクトが参照される。
  • 結果ファイル名が同一になり、保存のタイミング次第でA用の結果がBに出力されることがある。

対策

webpack.configのオブジェクトを毎回違うものにする。

var config = module.exports = function() {
    // 毎回別のもにして、生成する
    return {
        externals: {
            "jquery": "jQuery"
        },
        resolve: {
            root: "./js"
        },
        extensions: ['', '.js']
    };
};

そして、都度関数を呼び出して別のオブジェクトにする。

return gulp.src(ROOT_DIR + src)
       .pipe(webpack(require('./webpack.config.js')()))
       .pipe(rename(dst))
       .pipe(gulp.dest(DST_DIR));

一応このように対策したけど、なにかが間違っている気もするけどメモとして。

15
15
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
15
15