-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
61 lines (51 loc) · 1.2 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
require('shelljs/global');
const gulp = require('gulp4');
const notifier = require('node-notifier');
const devServer = require('gulp-develop-server');
// 是否是构建发布版本
let isRelease = process.argv.indexOf('-r') > 0;
const notify = (message, opt) => {
opt = opt || {};
notifier.notify({
title: 'Notify',
message: message,
sound: opt.sound === true, // Only Notification Center or Windows Toasters
});
};
gulp.task('clean', done => {
rm('-rf', 'dist');
done();
});
gulp.task('copy', () => {
return gulp.src([
'./src/**',
'./package.json'
])
.pipe(gulp.dest('./dist'));
});
gulp.task('serve', done => {
devServer.listen({ path: './src/index.js' }, err => {
if (err) {
console.error(err);
}
done();
});
});
gulp.task('restart', done => {
devServer.restart(err => {
if (err) {
console.error(err);
} else {
notify('Restart successfully.');
}
done();
});
});
gulp.task('watch', done => {
gulp.watch([
'./src/**/*'
], gulp.series('restart'));
done();
});
let tasks = isRelease ? ['clean', 'copy'] : ['serve', 'watch'];
gulp.task('default', gulp.series(...tasks, () => exec('start http://localhost:3333')));