This repository has been archived by the owner on Jun 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
89 lines (80 loc) · 1.55 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const gulp = require('gulp');
const ts = require('gulp-typescript');
const babel = require('gulp-babel');
const sq = require('gulp-sequence');
const del = require('del');
const isProd = process.env.NODE_ENV === 'production';
const SRC = 'src';
const TMP = '.tmp';
const DIST = 'dist';
const BABELRC = {
presets: [
[
'env',
{
targets: {
node: 'current',
},
spec: true,
modules: 'commonjs',
useBuiltIns: true,
},
],
...(isProd ? [
[
'minify',
{
replace: false,
removeConsole: false,
removeDebugger: true,
},
],
] : []),
],
plugins: [
'transform-function-bind',
'transform-object-rest-spread',
],
ignore: isProd
? [
'**/__mocks*__/*.js',
'**/__tests*__/*.dist.spec.js',
'**/__tests*__/*.spec.js',
]
: [],
};
gulp.task('ts', () =>
gulp.src([
`${SRC}/**/*.ts`,
])
.pipe(ts.createProject('./tsconfig.json')())
.pipe(gulp.dest(TMP)));
gulp.task('babel', () =>
gulp.src([
`${TMP}/**/*.js`,
])
.pipe(babel(BABELRC))
.pipe(gulp.dest(DIST)));
gulp.task('clean', () => del([
TMP,
DIST,
]));
gulp.task('clear', () => del([
TMP,
]));
gulp.task('copy', () => gulp.src([
`${TMP}/**/*`,
`!${TMP}/**/*.js`,
])
.pipe(gulp.dest(DIST)));
gulp.task('watch', () => {
gulp.watch([
`${SRC}/**/*.ts`,
], ['build']);
});
gulp.task('build', ['clean'], cb => sq(...[
'ts',
['babel', 'copy'],
'clear',
])(cb));
gulp.task('default', ['watch'], sq('build'));