-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
59 lines (49 loc) · 1.43 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
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const nodemon = require('gulp-nodemon');
const fsn = require('fs-nextra');
const ts = require('gulp-typescript');
const sourcemaps = require('gulp-sourcemaps');
const project = ts.createProject('tsconfig.json');
async function clean() {
await fsn.emptydir('dist');
}
gulp.task('backend', () => project.src()
.pipe(sourcemaps.init())
.pipe(project())
.js
.pipe(sourcemaps.write('.', { sourceRoot: '../src' }))
.pipe(gulp.dest('dist')));
gulp.task('views', () => gulp.src('src/views/**/*.ejs').pipe(gulp.dest('dist/views')));
gulp.task('serve', done => {
let started = false;
return nodemon({
watch: ['dist/**/*.js', 'dist/**/*.ejs'],
env: { NODE_ENV: 'development' },
ext: 'js'
})
.on('start', () => {
if (started) return;
started = true;
browserSync.init({
ghostMode: true,
proxy: 'http://localhost:80',
port: 3000,
reloadDelay: 1e3
});
done();
});
});
function reload(done, ms = 500) {
setTimeout(() => {
browserSync.reload();
done();
}, ms);
}
function watch() {
gulp.watch('src/views/**/*.ejs', gulp.series('views', reload));
gulp.watch('src/**/*.ts', gulp.series('backend', done => reload(done, 5e3)));
}
gulp.task('default', gulp.series(clean, 'backend', 'views'));
gulp.task('build', gulp.series(clean, 'backend', 'views'));
gulp.task('watch', gulp.series('build', gulp.parallel('serve', watch)));