-
Notifications
You must be signed in to change notification settings - Fork 29
/
babel.config.js
100 lines (96 loc) · 2.21 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
const plugins = [
// @see https://mui.com/guides/minimizing-bundle-size/
[
"babel-plugin-import",
{
libraryName: "@mui/material",
libraryDirectory: "",
camel2DashComponentName: false,
},
"core",
],
[
"babel-plugin-import",
{
libraryName: "@mui/icons-material",
libraryDirectory: "",
camel2DashComponentName: false,
},
"icons",
],
// @see https://github.com/ant-design/babel-plugin-import
[
"babel-plugin-import",
{
libraryName: "lodash",
libraryDirectory: "",
camel2DashComponentName: false, // default: true
},
],
];
// We need babel for code instrumentation
const enableCoverage = process.env.COVERAGE && process.env.COVERAGE !== "false";
if (enableCoverage) {
const debug = require("debug")("coverage");
debug("Enabling istanbul plugin in babel"); // eslint-disable-line no-console
plugins.push("istanbul");
}
// Add support of styled components
/*
plugins.push([
"styled-components",
{
ssr: true,
displayName: true,
preprocess: false,
},
]);
*/
// // Fix for pragmaFrag issue @see https://github.com/vercel/next.js/issues/11230
// 05/2022/ breaks Jest, it has been removed
// plugins.push([
// "@babel/plugin-transform-react-jsx",
// {
// runtime: "classic",
// },
// ]);
module.exports = {
// we also need next/babel preset to work with Next
presets: [
[
"next/babel",
{
"styled-jsx": {
plugins: ["styled-jsx-plugin-postcss"],
},
"preset-react": {
// runtime: "classic",
},
},
],
],
plugins,
// ESM support in Jest
babelrc: false,
env: {
// @see https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs
// @see https://bl.ocks.org/rstacruz/511f43265de4939f6ca729a3df7b001c
test: {
plugins: ["@babel/plugin-transform-modules-commonjs"],
presets: [
[
"next/babel",
{
"styled-jsx": {
plugins: ["styled-jsx-plugin-postcss"],
},
"preset-react": {
//needed somehow to avoid React messing the import
runtime: "automatic",
},
},
],
],
},
},
};