forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbabel.config.mjs
More file actions
84 lines (71 loc) · 2.33 KB
/
babel.config.mjs
File metadata and controls
84 lines (71 loc) · 2.33 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
import getBaseConfig from '@mui/internal-code-infra/babel-config';
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';
import generateReleaseInfo from './scripts/generateReleaseInfo.mjs';
const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
const errorCodesPath = path.resolve(dirname, './docs/public/static/error-codes.json');
/**
* @typedef {import('@babel/core')} babel
*/
/** @type {babel.ConfigFunction} */
export default function getBabelConfig(api) {
const baseConfig = getBaseConfig(api);
baseConfig.plugins.push([
'@mui/internal-babel-plugin-minify-errors',
{
detection: 'opt-out',
errorCodesPath,
outExtension: process.env.MUI_OUT_FILE_EXTENSION ?? undefined,
},
]);
const removePropTypesPlugin = baseConfig.plugins.find(
(p) => p[2] === 'babel-plugin-transform-react-remove-prop-types',
);
if (removePropTypesPlugin) {
removePropTypesPlugin[1] ??= {};
removePropTypesPlugin[1].mode = 'unsafe-wrap';
removePropTypesPlugin[1].ignoreFilenames ??= [];
removePropTypesPlugin[1].ignoreFilenames.push('DataGrid.tsx', 'DataGridPro.tsx');
}
const displayNamePlugin = baseConfig.plugins.find(
(p) => p[2] === '@mui/internal-babel-plugin-display-name',
);
if (displayNamePlugin) {
displayNamePlugin[1] ??= {};
displayNamePlugin[1].allowedCallees = {
...displayNamePlugin[1].allowedCallees,
'@mui/x-internals/forwardRef': ['forwardRef'],
};
}
if (process.env.NODE_ENV === 'production') {
if (!process.env.TEST_BUILD) {
baseConfig.plugins.push([
'babel-plugin-react-remove-properties',
{ properties: ['data-testid'] },
]);
}
if (process.env.BABEL_ENV) {
baseConfig.plugins.push([
'babel-plugin-search-and-replace',
{
rules: [
{
search: '__RELEASE_INFO__',
replace: generateReleaseInfo(),
},
],
},
]);
baseConfig.plugins.push([
'babel-plugin-transform-replace-expressions',
{
replace: [['__ALLOW_TEST_LICENSES__', 'false']],
},
]);
}
}
baseConfig.plugins.unshift(['@babel/plugin-transform-object-rest-spread', { loose: true }]);
delete baseConfig.assumptions.setSpreadProperties;
return baseConfig;
}