-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.js
108 lines (106 loc) · 3.13 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
module.exports = function (
api,
{ esm = true, extWhiteList = { ".example": ".example" } } = {}
) {
api.cache(true);
const samePlugIns = [
"reshow-object-to-json-parse",
"transform-react-pure-class-to-function",
["transform-react-remove-prop-types", { mode: "wrap" }],
"@babel/plugin-proposal-export-default-from",
"@babel/plugin-syntax-dynamic-import",
/**
* plugin-transform-classes need locate after plugin-transform-class-properties
* else will have Error: Missing class properties transform.
* cause by @babel/plugin-transform-classes
*/
"@babel/plugin-transform-class-properties",
"@babel/plugin-transform-classes",
"@babel/plugin-transform-arrow-functions",
"@babel/plugin-transform-nullish-coalescing-operator",
"@babel/plugin-transform-logical-assignment-operators",
"@babel/plugin-transform-object-assign",
"@babel/plugin-transform-object-rest-spread",
"@babel/plugin-transform-optional-chaining",
"@babel/plugin-transform-private-methods",
"@babel/plugin-transform-private-property-in-object",
"@babel/plugin-transform-react-constant-elements",
"@babel/plugin-transform-spread",
];
const cjsPlugins = [
...samePlugIns,
"add-module-exports",
"dynamic-import-node",
[
"reshow-transform-runtime",
{
// https://babel.dev/docs/en/babel-plugin-transform-runtime#regenerator
regenerator: true,
// https://github.com/react-atomic/reshow/tree/main/packages/reshow-app#transform-runtime-how-to-set-reshow-transform-runtime-versions
version: "7.18.3",
},
],
];
const esPlugins = [
...samePlugIns,
[
"reshow-transform-runtime",
{
// https://babel.dev/docs/en/babel-plugin-transform-runtime#regenerator
regenerator: true,
useESModules: true,
// https://github.com/react-atomic/reshow/tree/main/packages/reshow-app#transform-runtime-how-to-set-reshow-transform-runtime-versions
version: "7.18.3",
},
],
];
if (esm) {
cjsPlugins.push([
"reshow-import-extension",
{ extMapping: { ...extWhiteList, "": ".js" } },
]);
esPlugins.push([
"reshow-import-extension",
{ extMapping: { ...extWhiteList, "": ".mjs" } },
]);
}
const cjs = {
presets: [
[
"@babel/preset-env",
{
loose: true,
targets: ["last 2 versions", "ie >= 8"],
},
],
["@babel/preset-react", { runtime: "automatic" }],
],
plugins: cjsPlugins,
};
const es = {
presets: [
[
"@babel/preset-env",
{
modules: false,
loose: true,
/**
* Deploying ES2015+ Code in Production Today
*
* https://philipwalton.com/articles/deploying-es2015-code-in-production-today/
*/
targets: [
"Chrome >= 60",
"Safari >= 10.1",
"iOS >= 10.3",
"Firefox >= 54",
"Edge >= 15",
],
},
],
["@babel/preset-react", { runtime: "automatic" }],
],
plugins: esPlugins,
};
return { env: { cjs, es } };
};