-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
56 lines (47 loc) · 1.3 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
let gulp = require('gulp');
let ts = require('gulp-typescript');
let sourcemaps = require('gulp-sourcemaps');
let tsProject = ts.createProject('tsconfig.json');
let del = require('del');
let nodemon = require('gulp-nodemon');
let runSequence = require('run-sequence');
gulp.task('clean', () => {
return del([
tsProject.options.outDir
]);
});
gulp.task('compile', () => {
let tsResult = tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject());
return tsResult.js
.pipe(gulp.dest(tsProject.options.outDir))
.pipe(sourcemaps.write());
});
gulp.task('watch', () => {
return gulp.watch('src/**/*', ['compile']);
});
gulp.task('serve.prod', ['build', 'watch'], () => {
nodemon({
script: tsProject.options.outDir + '/index.js',
env: {
NODE_ENV: 'production'
}
}).on('restart', () => {
console.log('Node app restarted.');
});
});
gulp.task('serve.dev', ['build', 'watch'], () => {
nodemon({
script: tsProject.options.outDir + '/index.js',
watch: [tsProject.options.outDir],
env: {
NODE_ENV: 'development'
}
});
});
gulp.task('serve', ['serve.dev']);
gulp.task('build', (cb) => {
runSequence('clean', 'compile', cb);
});
gulp.task('default', ['serve']);