-
Notifications
You must be signed in to change notification settings - Fork 31
/
babel.config.js
96 lines (96 loc) · 3.26 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
// adapted from create-react-app
module.exports = function BabelConfig(api) {
if (api.caller(({ name }) => name === 'babel-jest')) {
// magic NODE_ENV to test when using babel-jest
// e.g. calling jest via npx on command-line
process.env.NODE_ENV = 'test'
}
return {
presets: [
[
'@babel/preset-env',
api.env('test')
? {
useBuiltIns: 'usage',
corejs: 3,
loose: true,
targets: {
node: 'current',
},
}
: {
useBuiltIns: 'usage',
modules: false,
corejs: 3,
loose: true,
exclude: ['transform-typeof-symbol'],
targets: [
'> 1.5%',
'Opera >= 58',
'Safari >= 12',
'Edge >= 75',
'Firefox ESR',
'not dead',
'not ie <= 11',
'not ie_mob <= 11',
],
},
],
[
'@babel/preset-react',
{
development: !api.env('production'),
useBuiltIns: true,
},
],
],
plugins: [
'@babel/plugin-proposal-optional-chaining',
[
'@babel/plugin-transform-destructuring',
{
// Use loose mode for performance:
// https://github.com/facebook/create-react-app/issues/5602
loose: true,
selectiveLoose: [
'useState',
'useEffect',
'useContext',
'useReducer',
'useCallback',
'useMemo',
'useRef',
'useImperativeHandle',
'useLayoutEffect',
'useDebugValue',
],
},
],
[
'@babel/plugin-proposal-class-properties',
{
loose: true,
},
],
[
'@babel/plugin-proposal-object-rest-spread',
{
useBuiltIns: true,
},
],
[
'@babel/plugin-transform-runtime',
{
corejs: false,
helpers: true,
regenerator: false,
useESModules: api.env(['development', 'production']),
},
],
'@babel/plugin-syntax-dynamic-import',
api.env('test') && 'babel-plugin-dynamic-import-node',
(!process.env.TEST_HOOKS || process.env.TEST_HOOKS === 'off') &&
'./scripts/removeTestAttrs',
].filter(Boolean),
}
}