-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
60 lines (51 loc) · 1.25 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
const gulp = require('gulp');
const log = require('fancy-log');
const rollup = require('rollup');
const del = require('del');
const DIST = 'dist';
function loadConfig() {
const rollupConfig = require('./rollup.conf');
return rollupConfig;
}
function clean() {
return del([DIST]);
}
function copy() {
return gulp.src('src/public/**').pipe(gulp.dest(DIST));
}
function buildJs() {
const rollupConfig = loadConfig();
return Promise.all(
rollupConfig.map(async (config) => {
const bundle = await rollup.rollup(config);
await bundle.write(config.output);
})
);
}
function watchJs() {
const rollupConfig = loadConfig();
const watcher = rollup.watch(rollupConfig);
watcher.on('event', (e) => {
if (e.code === 'ERROR') {
console.error();
console.error(`${e.error}`);
console.error();
} else if (e.code === 'BUNDLE_END') {
log(`Compilation success after ${e.duration}ms`);
}
});
}
function wrapError(handle) {
const wrapped = () =>
handle().catch((err) => {
log(err.toString());
});
wrapped.displayName = handle.name;
return wrapped;
}
function watch() {
watchJs();
}
exports.clean = clean;
exports.build = gulp.series(copy, buildJs);
exports.dev = gulp.series(copy, watch);