-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
38 lines (33 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
import gulp from 'gulp';
import babel from 'gulp-babel';
import rename from 'gulp-rename';
const BASE_DIR = './src';
const TYPESCRIPT_SOURCES = 'src/**/*.ts';
gulp.task('build:esm', () => buildEsm());
gulp.task('build:cjs', () => buildCommonjs());
gulp.task('watch:esm', watch(TYPESCRIPT_SOURCES, 'build:esm', buildEsm));
gulp.task('watch:cjs', watch(TYPESCRIPT_SOURCES, 'build:cjs', buildCommonjs));
function buildEsm(files = TYPESCRIPT_SOURCES) {
return gulp
.src(files, { base: BASE_DIR })
.pipe(babel({ extends: './babel.esm.config.json' }))
.pipe(rename((file) => (file.extname = '.mjs')))
.pipe(gulp.dest('build/esm/'));
}
function buildCommonjs(files = TYPESCRIPT_SOURCES) {
return gulp
.src(files, { base: BASE_DIR })
.pipe(babel({ extends: './babel.cjs.config.json' }))
.pipe(rename((file) => (file.extname = '.cjs')))
.pipe(gulp.dest('build/cjs/'));
}
function watch(files, build, incremental) {
return gulp.series(build, function () {
return gulp
.watch(files)
.on('ready', () => console.log('Watching files'))
.on('all', (event, path) => console.log(`[${event}] ${path}`))
.on('add', (path) => incremental(path))
.on('change', (path) => incremental(path));
});
}