-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbabel.config.js
More file actions
84 lines (76 loc) · 1.91 KB
/
babel.config.js
File metadata and controls
84 lines (76 loc) · 1.91 KB
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
module.exports = function getBabelConfig(api) {
const useESModules = api.env(["legacy", "module", "modern", "stable"]);
const presets = [];
presets.push(
[
"@babel/preset-typescript",
{
allowDeclareFields: true,
},
],
"@babel/preset-react"
);
if (api.env(["node", "commonjs", "module"])) {
const targets = {};
if (api.env("module")) targets.browsers = "> 0.5%, last 2 versions, not dead";
else if (api.env("commonjs")) targets.esmodules = true;
else if (api.env("node")) targets.node = "14";
presets.push([
"@babel/preset-env",
{
loose: true,
bugfixes: true,
debug: process.env.BUILD_VERBOSE === "verbose",
modules: useESModules ? false : "commonjs",
shippedProposals: api.env("modern"),
forceAllTransforms: false,
targets,
},
]);
}
const plugins = [
[
"@babel/plugin-transform-typescript",
{
allowDeclareFields: true,
},
],
];
if (!api.env("module")) {
plugins.push(
"babel-plugin-optimize-clsx",
// Need the following 3 proposals for all targets in .browserslistrc.
// With our usage the transpiled loose mode is equivalent to spec mode.
["@babel/plugin-proposal-class-properties", { loose: true }],
["@babel/plugin-proposal-private-methods", { loose: true }],
["@babel/plugin-proposal-object-rest-spread", { loose: true }]
);
}
plugins.push(
["@babel/plugin-proposal-decorators", { loose: true, decoratorsBeforeExport: true }],
[
"@babel/plugin-transform-runtime",
{
useESModules,
// any package needs to declare 7.4.4 as a runtime dependency. default is ^7.0.0
version: "^7.21.0",
},
]
);
if (api.env("module")) {
plugins.push("babel-plugin-add-import-extension");
}
if (api.env(["node", "commonjs"])) {
plugins.push([
"babel-plugin-transform-react-remove-prop-types",
{
mode: "unsafe-wrap",
},
]);
}
return {
presets,
plugins,
ignore: [/@babel[\\|/]runtime/],
};
};