Repository navigation
Expand file tree
/
Copy pathbabel.config.mjs
More file actions
78 lines (65 loc) · 2.15 KB
/
Copy pathbabel.config.mjs
File metadata and controls
78 lines (65 loc) · 2.15 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
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 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']],
},
]);
}
}
// Babel 8 deprecates the plugin's `loose` option in favour of the four assumptions it used to
// set. `objectRestNoSymbols` and `setSpreadProperties` already come from the base config.
baseConfig.plugins.unshift('@babel/plugin-transform-object-rest-spread');
baseConfig.assumptions.ignoreFunctionLength = true;
baseConfig.assumptions.pureGetters = true;
return baseConfig;
}