-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
71 lines (61 loc) · 1.71 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const gulp = require("gulp");
const webpack = require("webpack");
const tasks = require("./tasks/gulptasks.js");
const { argv } = require("yargs");
const browserSync = require("browser-sync").create();
process.env.NODE_ENV = argv.production || "development";
const webpackConfig =
process.env.NODE_ENV === "production" ? "./webpack.config.prod.js" : "./webpack.config.js";
// run webpack to compile the script into a bundle
function compile(done) {
return new Promise((resolve, reject) => {
webpack(require(webpackConfig), (err, stats) => {
if (err) {
return reject(err);
}
if (stats.hasErrors()) {
return reject(new Error(stats));
}
resolve();
});
});
}
function serve(done) {
browserSync.init(
{
server: "./build",
port: 8080,
host: "0.0.0.0"
},
done
);
}
function watch(done) {
return gulp.watch(
"**/*", // watch everything...
{
ignored: [
// ...except for things generated by the build process.
"build/**/*"
]
},
// when something changes, rebuild + reload
gulp.series(compile, reload)
);
}
function reload(done) {
browserSync.reload();
done();
}
gulp.task("copy:html", tasks.copyHtml);
gulp.task("copy:css", tasks.copyCss);
gulp.task("copy:assets", tasks.copyAssets);
gulp.task(
"server",
gulp.series(tasks.clean, tasks.copyAssets, tasks.copyHtml, tasks.copyCss, compile, serve, watch)
);
// default includes all
gulp.task(
"default",
gulp.series(tasks.clean, tasks.copyAssets, tasks.copyHtml, tasks.copyCss, compile)
);