-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
53 lines (45 loc) · 1.51 KB
/
gulpfile.js
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
var gulp = require("gulp");
var gutil = require("gulp-util");
var webpack = require("webpack");
var webpackConfig = require("./webpack.config.js");
var WebpackDevServer = require("webpack-dev-server");
// The development server (the recommended option for development)
gulp.task("default", ["webpack-dev-server"]);
gulp.task("webpack-dev-server", function (callback) {
webpackConfig.output.path = "/static";
var compiler = webpack(webpackConfig);
// Start a webpack-dev-server
new WebpackDevServer(compiler, {
contentBase: "./static/",
filename: "./static/bundle.js",
watchDelay: 300,
publicPath: "/",
headers: {
"X-Custom-Header": "yes"
},
stats: {
colors: true
},
}).listen(8080, "localhost", function (err) {
if (err) throw new gutil.PluginError("webpack-dev-server", err);
gutil.log("[webpack-dev-server]", "http://localhost:8080/");
});
});
// Build and watch cycle (another option for development)
// Advantage: No server required, can run app from filesystem
// Disadvantage: Requests are not blocked until bundle is available,
// can serve an old app on refresh
gulp.task("build", ["webpack:build-dev"], function () {
gulp.watch(["src/**/*"], ["webpack:build-dev"]);
});
gulp.task("webpack:build-dev", function (callback) {
var compiler = webpack(webpackConfig);
// run webpack
compiler.run(function (err, stats) {
if (err) throw new gutil.PluginError("webpack:build-dev", err);
gutil.log("[webpack:build-dev]", stats.toString({
colors: true
}));
callback();
});
});