-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
47 lines (39 loc) · 1.16 KB
/
gulpfile.babel.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
import gulp from 'gulp';
import gutil from "gulp-util";
import watch from 'gulp-watch';
import path from 'path';
import BrowserSync from 'browser-sync';
import rollup from 'rollup-stream';
import source from 'vinyl-source-stream';
import rollupConfig from './rollup.config';
const dist = "dist";
const tmp = ".tmp";
const browserSync = BrowserSync.create();
let watchPhase = false;
const handleErrors = (plugin, name) => {
plugin.on('error', err => {
if(!watchPhase) {
throw new gutil.PluginError(name, err)
}
gutil.log(gutil.colors.red(`[${name}]`), err);
plugin.emit('end');
});
return plugin;
};
gulp.task("js", () =>
handleErrors(rollup(Object.assign({}, rollupConfig)), "rollup")
.pipe(source(path.join('cms', 'index.js')))
.pipe(gulp.dest(tmp))
.pipe(gulp.dest(dist))
.pipe(browserSync.stream())
);
gulp.task('serve', ['js'], () => {
browserSync.init({
server: {
baseDir: [tmp, './']
},
open: false
});
watch("cms/**/*.js", () => { watchPhase = true; gulp.start(["js"]) });
watch("**/*.html", () => { browserSync.reload() });
});