forked from catima/catima
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbabel.config.js
More file actions
56 lines (51 loc) · 1.75 KB
/
babel.config.js
File metadata and controls
56 lines (51 loc) · 1.75 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
// babel.config.js
module.exports = function (api) {
const defaultConfigFunc = require("shakapacker/package/babel/preset.js");
const resultConfig = defaultConfigFunc(api);
const isDevelopmentEnv = api.env("development");
const isProductionEnv = api.env("production");
const isTestEnv = api.env("test");
const changesOnDefault = {
presets: [
[
"@babel/preset-react",
{
development: isDevelopmentEnv || isTestEnv,
useBuiltIns: true,
runtime: "automatic", // Important for React 17 JSX transform
},
],
].filter(Boolean),
plugins: [
// Don't add @babel/plugin-transform-runtime here since it's already in Shakapacker preset
isProductionEnv && [
"babel-plugin-transform-react-remove-prop-types",
{
removeImport: true,
},
],
process.env.WEBPACK_SERVE && "react-refresh/babel",
].filter(Boolean),
};
// Override the transform-runtime plugin instead of adding it
const existingPlugins = resultConfig.plugins || [];
const transformRuntimeIndex = existingPlugins.findIndex(
(plugin) =>
Array.isArray(plugin) && plugin[0] === "@babel/plugin-transform-runtime",
);
if (transformRuntimeIndex !== -1) {
// Replace the existing transform-runtime plugin with our configuration
resultConfig.plugins[transformRuntimeIndex] = [
"@babel/plugin-transform-runtime",
{
helpers: true,
regenerator: true,
useESModules: true,
version: require("@babel/runtime/package.json").version,
},
];
}
resultConfig.presets = [...resultConfig.presets, ...changesOnDefault.presets];
resultConfig.plugins = [...resultConfig.plugins, ...changesOnDefault.plugins];
return resultConfig;
};