-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path.babelrc.js
84 lines (81 loc) · 2.4 KB
/
.babelrc.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
// const browserlist = [
// '>= 1%',
// 'last 1 major version',
// 'not dead',
// 'Chrome >= 41',
// 'Firefox >= 38',
// 'Edge >= 12',
// 'Explorer >= 10',
// 'iOS >= 9',
// 'Safari >= 9',
// 'Android >= 4.4',
// 'Opera >= 30',
// ];
module.exports = (api) => {
const env = api.env();
console.log('====babel env====', env);
let dev = false;
let modules;
switch (env) {
case 'docs':
case 'test':
case 'dist-dev':
dev = true;
modules = false;
break;
case 'dist-prod':
case 'esm':
modules = false;
break;
case 'cjs':
default:
modules = 'commonjs';
}
return {
presets: [
[
'@babel/preset-env',
{
modules,
// Allow importing core-js in entrypoint and use browserlist to select polyfills
// 若将@babel/preset-env的useBuiltIns选项值设置为 usage,同时把node_modules从babel-loader中exclude,会导致babel 无法检测到nodes_modules中所需要的polyfill。"useBuiltIns: usage" for node_modules without transpiling #9419,在未支持该issue提到的内容之前,请将useBuiltIns设置为entry,或者不要把node_modules从babel-loader中exclude。
useBuiltIns: 'entry',
// Set the corejs version we are using to avoid warnings in console
// This will need to change once we upgrade to corejs@3
corejs: 3,
// loose: true,
ignoreBrowserslistConfig: true,
shippedProposals: true,
include: ['proposal-object-rest-spread'],
// targets: {
// browsers: browserlist,
// },
// Exclude transforms that make all code slower
exclude: ['transform-typeof-symbol'],
},
],
[
'@babel/preset-react',
{
// Adds component stack to warning messages
// Adds __self attribute to JSX which React will use for some warnings
// development: isEnvDevelopment || isEnvTest,
// Will use the native built-in instead of trying to polyfill
// behavior for any plugins that require one.
useBuiltIns: true,
},
],
'@babel/preset-typescript',
],
plugins: [
'transform-remove-console',
'@babel/transform-class-properties',
[
'@babel/plugin-transform-runtime',
{
useESModules: !modules,
},
],
],
};
};