-
-
Notifications
You must be signed in to change notification settings - Fork 595
/
Copy pathgulpfile.js
55 lines (49 loc) · 1.73 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
const babel = require('gulp-babel');
const gulp = require('gulp');
const path = require('path');
const watch = require('gulp-watch');
const BUILD = process.env.PARSE_BUILD || 'browser';
const transformRuntime = ["@babel/plugin-transform-runtime", {
"corejs": 3,
"helpers": true,
"regenerator": true,
"useESModules": false
}];
const PRESETS = {
'browser': ["@babel/preset-typescript", ["@babel/preset-env", {
"targets": "> 0.25%, not dead"
}]],
'weapp': ["@babel/preset-typescript", ["@babel/preset-env", {
"targets": "> 0.25%, not dead"
}], '@babel/react'],
'node': ["@babel/preset-typescript", ["@babel/preset-env", {
"targets": { "node": "14" }
}]],
'react-native': ["@babel/preset-typescript", 'module:metro-react-native-babel-preset'],
};
const PLUGINS = {
'browser': [transformRuntime, '@babel/plugin-proposal-class-properties',
['transform-inline-environment-variables', {'exclude': ['SERVER_RENDERING']}]],
'weapp': [transformRuntime, '@babel/plugin-proposal-class-properties',
['transform-inline-environment-variables', {'exclude': ['SERVER_RENDERING']}]],
'node': ['transform-inline-environment-variables'],
'react-native': ['transform-inline-environment-variables']
};
function compileTask(stream) {
return stream
.pipe(babel({
presets: PRESETS[BUILD],
plugins: PLUGINS[BUILD],
}))
// Second pass to kill BUILD-switched code
.pipe(babel({
plugins: ['minify-dead-code-elimination'],
}))
.pipe(gulp.dest(path.join('lib', BUILD)));
}
gulp.task('compile', function() {
return compileTask(gulp.src('src/*.*(js|ts)'));
});
gulp.task('watch', function() {
return compileTask(watch('src/*.*(js|ts)', { ignoreInitial: false, verbose: true }));
});