-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
67 lines (59 loc) · 1.46 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
const del = require("del");
const gulp = require("gulp");
const minimist = require("minimist");
const webpack = require("webpack");
const webpack_stream = require("webpack-stream");
/**
* Build target browser.
*/
const BROWSER = minimist(process.argv.slice(2)).browser || "chrome";
/**
* Constants.
*/
const OUTPUT_DIR = "build/";
const WEBPACK_CONFIG = require("./webpack.config.js");
/**
* Webpack plugins.
*/
WEBPACK_CONFIG.plugins = WEBPACK_CONFIG.plugins || [];
WEBPACK_CONFIG.plugins.push(
new webpack.DefinePlugin({ BROWSER_ENV: JSON.stringify(BROWSER) })
);
/**
* Build project.
*/
exports.build = gulp.series(clean, gulp.parallel(js, static), watcher);
/**
* Clean old files before building new ones.
*/
function clean() {
return del([OUTPUT_DIR]);
}
/**
* Build js code.
*/
function js() {
return gulp
.src("(src|example)/**/*.js", { base: "example" })
.pipe(webpack_stream(WEBPACK_CONFIG, webpack))
.pipe(gulp.dest(OUTPUT_DIR))
.on("error", (error) => process.stderr.write(`${error}\n`));
}
/**
* Copy static files.
*/
function static() {
return gulp
.src("example/**/!(*.js)", { base: "example" })
.pipe(gulp.dest(OUTPUT_DIR));
}
/**
* Watch changes of files.
*
* @param {Function} done execute done to inform gulp that the task is finished
*/
function watcher(done) {
gulp.watch("(src|example)/**/*.js").on("change", gulp.series(js));
gulp.watch("example/**/!(*.js)").on("change", gulp.series(static));
done();
}