Skip to content

Commit

Permalink
[core] Update babel configs (#9713)
Browse files Browse the repository at this point in the history
  • Loading branch information
romgrk authored Aug 30, 2023
1 parent 5e0aa1d commit 55afbc8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 48 deletions.
14 changes: 5 additions & 9 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,15 @@ module.exports = function getBabelConfig(api) {
]);
}
}
if (process.env.NODE_ENV === 'test') {
plugins.push([
'babel-plugin-module-resolver',
{
alias: defaultAlias,
root: ['./'],
},
]);
}

return {
assumptions: {
noDocumentAll: true,
// TODO: Replace "loose" mode with these:
// setPublicClassFields: true,
// privateFieldsAsProperties: true,
// objectRestNoSymbols: true,
// setSpreadProperties: true,
},
presets,
plugins,
Expand Down
68 changes: 29 additions & 39 deletions docs/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fse = require('fs-extra');
const getBaseConfig = require('../babel.config');

const alias = {
'@mui/x-data-grid': '../packages/grid/x-data-grid/src',
Expand All @@ -22,45 +23,34 @@ const { version: transformRuntimeVersion } = fse.readJSONSync(
require.resolve('@babel/runtime-corejs2/package.json'),
);

module.exports = {
presets: [
// backport of https://github.com/zeit/next.js/pull/9511
['next/babel', { 'transform-runtime': { corejs: 2, version: transformRuntimeVersion } }],
],
plugins: [
[
'babel-plugin-transform-rename-import',
{
replacements: [{ original: '@mui/utils/macros/MuiError.macro', replacement: 'react' }],
},
],
'babel-plugin-optimize-clsx',
// for IE 11 support
'@babel/plugin-transform-object-assign',
'babel-plugin-preval',
[
'babel-plugin-module-resolver',
{
alias,
transformFunctions: ['require', 'require.context'],
},
module.exports = function getBabelConfig(api) {
const baseConfig = getBaseConfig(api);

return {
assumptions: baseConfig.assumptions,
presets: [
// backport of https://github.com/zeit/next.js/pull/9511
['next/babel', { 'transform-runtime': { corejs: 2, version: transformRuntimeVersion } }],
],
],
ignore: [
// Fix a Windows issue.
/@babel[\\|/]runtime/,
// Fix const foo = /{{(.+?)}}/gs; crashing.
/prettier/,
/@mui[\\|/]docs[\\|/]markdown/,
],
env: {
production: {
plugins: [
// TODO fix useGridSelector side effect and enable back.
// '@babel/plugin-transform-react-constant-elements',
['babel-plugin-react-remove-properties', { properties: ['data-mui-test'] }],
['babel-plugin-transform-react-remove-prop-types', { mode: 'remove' }],
plugins: [
...baseConfig.plugins,
[
'babel-plugin-transform-rename-import',
{
replacements: [{ original: '@mui/utils/macros/MuiError.macro', replacement: 'react' }],
},
],
},
},
// for IE 11 support
'@babel/plugin-transform-object-assign',
'babel-plugin-preval',
[
'babel-plugin-module-resolver',
{
alias,
transformFunctions: ['require', 'require.context'],
},
],
],
ignore: [...baseConfig.ignore, /@mui[\\|/]docs[\\|/]markdown/],
};
};

0 comments on commit 55afbc8

Please sign in to comment.