-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathbabel.config.js
123 lines (115 loc) · 2.28 KB
/
babel.config.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
module.exports = function (api) {
api.cache(true);
const envNames = [
'esm',
'cjs',
'rollupUmd',
'rollupUmdPolyfill',
'rollupEsm',
'rollupEsmPolyfill',
];
const getPresetEnvOption = (envName) => {
const options = {
esm: {
modules: false,
targets: {
node: '12',
},
},
cjs: {
modules: 'commonjs',
targets: {
node: '10',
},
},
rollupUmd: {
bugfixes: true,
modules: false,
},
rollupUmdPolyfill: {
bugfixes: true,
modules: false,
},
rollupEsm: {
bugfixes: true,
modules: false,
targets: {
esmodules: true,
},
},
rollupEsmPolyfill: {
bugfixes: true,
modules: false,
targets: {
esmodules: true,
},
},
};
return options[envName];
};
const getTransformRuntimeOption = (envName) => {
const version = '^7.9.0';
const corejs = {
version: 3,
proposals: true,
};
const options = {
esm: {
useESModules: true,
version,
},
cjs: {
useESModules: false,
version,
},
rollupUmd: {
useESModules: true,
version,
},
rollupUmdPolyfill: {
useESModules: true,
version,
corejs,
},
rollupEsm: {
useESModules: true,
version,
},
rollupEsmPolyfill: {
useESModules: true,
version,
corejs,
},
};
return options[envName];
};
const getPresets = (envName) => [
['@babel/preset-env', getPresetEnvOption(envName)],
'@babel/preset-react',
[
'@babel/preset-typescript',
{
allowDeclareFields: true,
},
],
];
const getPlugins = (envName) => [
['@babel/plugin-transform-runtime', getTransformRuntimeOption(envName)],
// For typescript
'@babel/proposal-class-properties',
'@babel/proposal-object-rest-spread',
];
return {
env: envNames.reduce(
(envOptions, envName) => ({
...envOptions,
[envName]: {
presets: getPresets(envName),
plugins: getPlugins(envName),
},
}),
{},
),
sourceMaps: 'inline',
};
};