Skip to content

Commit

Permalink
Update babel.config.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot committed Feb 5, 2025
1 parent f4250cf commit 1a5a26e
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ function resolveAliasPath(relativeToBabelConf) {
return `./${resolvedPath.replace('\\', '/')}`;
}

/** @type {babel.PluginItem[]} */
const productionPlugins = [
['babel-plugin-react-remove-properties', { properties: ['data-testid'] }],
];

/** @type {babel.ConfigFunction} */
module.exports = function getBabelConfig(api) {
const useESModules = api.env(['regressions', 'modern', 'stable']);
Expand Down Expand Up @@ -63,14 +68,9 @@ module.exports = function getBabelConfig(api) {
'@babel/preset-typescript',
];

const usesAliases =
// in this config:
api.env(['coverage', 'development', 'test', 'benchmark']) ||
process.env.NODE_ENV === 'test' ||
// in webpack config:
api.env(['regressions']);

const outFileExtension = '.js';
// Essentially only replace in production builds.
// When aliasing we want to keep the original extension
const outFileExtension = process.env.MUI_OUT_FILE_EXTENSION || null;

/** @type {babel.PluginItem[]} */
const plugins = [
Expand Down Expand Up @@ -113,15 +113,16 @@ module.exports = function getBabelConfig(api) {
[
'@mui/internal-babel-plugin-resolve-imports',
{
// Don't replace the extension when we're using aliases.
// Essentially only replace in production builds.
outExtension: usesAliases ? null : outFileExtension,
outExtension: outFileExtension,
},
],
]
: []),
];

if (process.env.NODE_ENV === 'production') {
plugins.push(...productionPlugins);
}
if (process.env.NODE_ENV === 'test') {
plugins.push([
'babel-plugin-module-resolver',
Expand Down Expand Up @@ -190,6 +191,7 @@ module.exports = function getBabelConfig(api) {
},
benchmark: {
plugins: [
...productionPlugins,
[
'babel-plugin-module-resolver',
{
Expand Down

0 comments on commit 1a5a26e

Please sign in to comment.