-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathbabel.config.js
More file actions
79 lines (73 loc) · 2.33 KB
/
Copy pathbabel.config.js
File metadata and controls
79 lines (73 loc) · 2.33 KB
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
/**
* The esm build targets modern browsers that support native `class` syntax.
* Down-transpiling classes there only pulls in @babel/runtime helper imports
* (inheritsLoose, createClass, readOnlyError, wrapNativeSuper) and extra bytes
* for no benefit, so the class transforms only run for the es5/CJS build.
*
* Only the class-related transforms are made conditional. The other syntax
* transforms (block-scoping, template-literals, ...) do not emit @babel/runtime
* helpers, so keeping them in both builds preserves the existing runtime
* behavior (e.g. `const`/`let` hoisting) while still dropping the helpers.
*/
const isEs5 = process.env['NODE_ENV'] === 'es5';
// only include the given class-lowering plugins for the es5/CJS build.
const classOnly = (pluginList) => (isEs5 ? pluginList : []);
const plugins = [
'@babel/plugin-transform-explicit-resource-management',
'@babel/plugin-transform-typescript',
/**
* Must run before @babel/plugin-transform-classes,
* otherwise babel throws 'Missing class properties transform'.
*/
...classOnly(['@babel/plugin-transform-class-properties']),
['@babel/transform-template-literals', {
'loose': true
}],
'@babel/transform-literals',
'@babel/transform-block-scoped-functions',
...classOnly([
['@babel/plugin-transform-classes', {
'loose': true
}]
]),
'@babel/transform-sticky-regex',
'@babel/transform-unicode-regex',
'@babel/transform-block-scoping',
['@babel/transform-runtime', {
'regenerator': false
}],
'@babel/plugin-transform-react-jsx'
];
let presets = [
[
'@babel/typescript',
{
rewriteImportExtensions: true,
loose: true,
modules: false
}
]
];
// console.log('babel: NODE_ENV: ' + process.env['NODE_ENV']);
if (isEs5) {
presets = [
[
'@babel/typescript',
{
rewriteImportExtensions: true,
loose: true,
targets: {
edge: '107',
firefox: '107',
chrome: '108',
safari: '16.2'
},
useBuiltIns: false
}]
];
plugins.unshift('@babel/plugin-transform-modules-commonjs');
}
module.exports = {
presets,
plugins
};