-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgulpfile.babel.js
61 lines (53 loc) · 1.54 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import gulp from 'gulp';
import mocha from 'gulp-mocha';
import ts from 'gulp-typescript';
import webpack from 'webpack';
import webpackStream from 'webpack-stream';
import webpackConfig from './webpack.config.babel';
const tsProject = ts.createProject('tsconfig.json');
const routes = {
typescript: {
src: 'src/**/*.ts',
dest: 'dist',
},
test: 'test/**/*.ts',
};
// Compile TypeScript files
const typescript = () =>
tsProject
.src()
.pipe(tsProject())
.js.pipe(gulp.dest(routes.typescript.dest));
// Run tests
const test = () =>
gulp.src(routes.test, { read: false })
.pipe(mocha({
reporter: 'list',
require: ['ts-node/register'],
exit: true,
}))
.on('error', console.error);
// Webpack bundling
const webpackTask = (callback) => {
webpackStream(webpackConfig, webpack)
.pipe(gulp.dest(routes.typescript.dest))
.on('end', callback)
.on('error', (err) => {
console.error(err);
callback(err);
});
};
// Watch files for changes
const watch = () => {
gulp.watch(routes.typescript.src, gulp.series(typescript, webpackTask));
gulp.watch(routes.test, test);
};
// Define Gulp tasks
export const dev = gulp.series(typescript, webpackTask, test, watch);
export const build = gulp.series(typescript, webpackTask);
export const runTest = test;
export default dev;
// Export individual tasks for CLI usage
exports.test = test;
exports.typescript = typescript;
exports.webpack = webpackTask;