Skip to content

Commit

Permalink
Cleanup babel config
Browse files Browse the repository at this point in the history
  • Loading branch information
brijeshb42 committed May 9, 2024
1 parent 29df62a commit 27cc5dc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 154 deletions.
55 changes: 1 addition & 54 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
const path = require('path');

const errorCodesPath = path.resolve(__dirname, './docs/public/static/error-codes.json');
const missingError = process.env.MUI_EXTRACT_ERROR_CODES === 'true' ? 'write' : 'annotate';

function resolveAliasPath(relativeToBabelConf) {
const resolvedPath = path.relative(process.cwd(), path.resolve(__dirname, relativeToBabelConf));
return `./${resolvedPath.replace('\\', '/')}`;
}

const productionPlugins = [
['babel-plugin-react-remove-properties', { properties: ['data-mui-test'] }],
];

module.exports = function getBabelConfig(api) {
const useESModules = api.env(['regressions', 'legacy', 'modern', 'stable', 'rollup']);

const defaultAlias = {
'@pigment-css/react': resolveAliasPath('./packages/pigment-css-react/src'),
docs: resolveAliasPath('./docs'),
test: resolveAliasPath('./test'),
'@mui-internal/api-docs-builder': resolveAliasPath(
'./node_modules/@mui/monorepo/packages/api-docs-builder',
),
};

const presets = [
Expand All @@ -44,42 +32,8 @@ module.exports = function getBabelConfig(api) {
'@babel/preset-typescript',
];

const plugins = [
[
'babel-plugin-macros',
{
muiError: {
errorCodesPath,
missingError,
},
},
],
'babel-plugin-optimize-clsx',
// Need the following 3 proposals for all targets in .browserslistrc.
// With our usage the transpiled loose mode is equivalent to spec mode.
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-private-methods', { loose: true }],
['@babel/plugin-proposal-private-property-in-object', { loose: true }],
['@babel/plugin-proposal-object-rest-spread', { loose: true }],
[
'@babel/plugin-transform-runtime',
{
useESModules,
// any package needs to declare 7.4.4 as a runtime dependency. default is ^7.0.0
version: '^7.4.4',
},
],
[
'babel-plugin-transform-react-remove-prop-types',
{
mode: 'unsafe-wrap',
},
],
];
const plugins = [];

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 @@ -140,12 +94,6 @@ module.exports = function getBabelConfig(api) {
],
],
},
legacy: {
plugins: [
// IE11 support
'@babel/plugin-transform-object-assign',
],
},
test: {
sourceMaps: 'both',
plugins: [
Expand All @@ -160,7 +108,6 @@ module.exports = function getBabelConfig(api) {
},
benchmark: {
plugins: [
...productionPlugins,
[
'babel-plugin-module-resolver',
{
Expand Down
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,14 @@
"validate-declarations": "tsx scripts/validateTypescriptDeclarations.mts"
},
"dependencies": {
"@pigment-css/react": "workspace:^"
"@pigment-css/react": "workspace:^",
"globby": "^14.0.1"
},
"devDependencies": {
"@argos-ci/core": "^2.0.0",
"@babel/cli": "^7.24.1",
"@babel/core": "^7.24.4",
"@babel/node": "^7.23.9",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@babel/plugin-proposal-private-methods": "^7.18.6",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/plugin-transform-object-assign": "^7.24.1",
"@babel/plugin-transform-react-constant-elements": "^7.24.1",
"@babel/plugin-transform-runtime": "^7.24.3",
"@babel/preset-env": "^7.24.4",
Expand Down
97 changes: 3 additions & 94 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 27cc5dc

Please sign in to comment.