This repository was archived by the owner on Jul 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgulpfile.js
More file actions
57 lines (47 loc) · 1.51 KB
/
gulpfile.js
File metadata and controls
57 lines (47 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"use strict";
const gulp = require("gulp");
const gutil = require("gulp-util");
const webpack = require("webpack");
const minimist = require("minimist");
const browserSync = require("browser-sync");
const config = require("./webpack.config.js");
const syncOptions = {
server: {
baseDir: "./",
index: "index.html"
}
};
gulp.task("webpack", function() {
const env = minimist(process.argv.slice(2));
let options = Object.create(config);
if (env["min"]) {
options.output.filename = "./js/build/bundle.min.js";
options.plugins.push(new webpack.optimize.UglifyJsPlugin());
}
if (env["watch"] || env["browser-sync"]) {
options.watch = true;
}
webpack(options, function(err, stats) {
if (err) {
throw new gutil.PluginError("webpack", err);
}
gutil.log("[webpack]", stats.toString());
});
if (env["browser-sync"]) {
browserSync(syncOptions);
gulp.watch(["./js/build/**", "./index.html", "./css/**"], function() {
browserSync.reload();
});
}
});
gulp.task("serve", ["webpack"], function() {
syncOptions.ghostMode = false;
browserSync(syncOptions);
});
// Gulp コマンド
// readme.mdに書いてもいいが、開発時はgulpをグローバルにインストールしたくないため、
// npm run から叩くので、ここに書いておく。
// gulp webpack -> 普通に1回ビルド
// 引数:
// --min : UglifyJsPluginをかける。出力はbundle.min.jsなので注意
// --browser-sync : browser-syncで監視する。--watchもされる。