-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
84 lines (73 loc) · 1.81 KB
/
index.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
/**
* [ES2022+]
* https://babeljs.io/docs/en/babel-preset-env
*
* [React]
* https://babeljs.io/docs/en/babel-preset-react
*
* [Flow]
* https://babeljs.io/docs/en/babel-preset-flow
*
* [Hermes Parser]
* https://github.com/facebook/hermes/blob/main/tools/hermes-parser/js/babel-plugin-syntax-hermes-parser
*
* [Ponyfills]
* https://babeljs.io/docs/en/babel-plugin-transform-runtime
*/
/**
* [Notes]
*
* Presets are run in the reverse order they are defined.
* Plugins are run in the order they are defined below,
* but they are run *before* presets.
*/
/**
* 1. Will be set as default from Babel 8.
*
* 2. Ensure all helpers are imported instead of inlined.
* See https://github.com/babel/babel/issues/9297#issuecomment-453750049
*
* 3. https://babeljs.io/docs/babel-generator#:~:text=importAttributesKeyword
*
* 4. https://babeljs.io/docs/babel-preset-flow#allowdeclarefields
* See `Regression: Flow void class properties` test.
*/
module.exports = (context, options = {}) => {
let { parser = 'babel', ...envOptions } = options;
let configOpts = {
generatorOpts: {
importAttributesKeyword: 'with', // 3
},
};
let envOpts = {
bugfixes: true, // 1
...envOptions,
};
let reactOpts = {
useSpread: true, // 1
runtime: 'automatic', // 1
};
let runtimeOpts = {
corejs: 3,
helpers: true,
regenerator: true,
version: '7.26.0', // 2
};
let flowOpts = {
// allowDeclareFields: true, // 4
};
let presets = [
['@babel/preset-env', envOpts],
['@babel/preset-react', reactOpts],
['@babel/preset-flow', flowOpts],
];
let plugins = [
...(parser === 'hermes' ? ['babel-plugin-syntax-hermes-parser'] : []),
['@babel/plugin-transform-runtime', runtimeOpts],
];
return {
...configOpts,
presets,
plugins,
};
};