-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
56 lines (48 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
const del = require('del');
const gulp = require('gulp');
const babel = require('gulp-babel');
const sourcemaps = require('gulp-sourcemaps');
const babelConfig = require('./package.json').babel;
function _build({ destination, moduleType }) {
return gulp
.src('src/**/*.js', { ignore: 'src/**/*.spec.js' })
.pipe(sourcemaps.init())
.pipe(
babel({
presets: babelConfig.presets.map((presetConfig) => {
const hasOptions = Array.isArray(presetConfig);
const presetName = hasOptions ? presetConfig[0] : presetConfig;
const presetOptions = hasOptions ? presetConfig[1] : undefined;
if (presetName !== 'env') {
return presetConfig;
}
return [
presetName,
{
...presetOptions,
modules: moduleType
}
];
})
})
)
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(destination));
}
function cjs() {
return _build({ destination: 'lib', moduleType: 'commonjs' });
}
function clean(cb) {
return del(['esm/**/*', 'lib/**/*']);
}
function esm() {
return _build({ destination: 'esm', moduleType: false });
}
function watchModules() {
return gulp.watch('./src/**/*', gulp.parallel(cjs, esm));
}
exports.build = gulp.series(clean, gulp.parallel(cjs, esm));
exports.clean = clean;
exports.cjs = cjs;
exports.esm = esm;
exports.watch = gulp.series(clean, cjs, esm, watchModules);