๐Ÿ“ฆ mui / base-ui

๐Ÿ“„ babel.config.mjs ยท 49 lines
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
49import getBaseConfig from '@mui/internal-code-infra/babel-config';
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';

const dirname = path.dirname(fileURLToPath(import.meta.url));

const errorCodesPath = path.join(dirname, 'docs/src/error-codes.json');

export default function getBabelConfig(api) {
  const baseConfig = getBaseConfig(api);

  const plugins = [
    [
      '@mui/internal-babel-plugin-minify-errors',
      {
        missingError: 'annotate',
        runtimeModule: '#formatErrorMessage',
        detection: 'opt-out',
        errorCodesPath,
      },
    ],
  ];

  const displayNamePlugin = baseConfig.plugins.find(
    (p) => p[2] === '@mui/internal-babel-plugin-display-name',
  );
  displayNamePlugin[1].allowedCallees ??= {};
  displayNamePlugin[1].allowedCallees['@base-ui/utils/fastHooks'] = [
    'fastComponent',
    'fastComponentRef',
  ];

  return {
    ...baseConfig,
    plugins: [...baseConfig.plugins, ...plugins],
    overrides: [
      {
        exclude: /\.test\.(js|ts|tsx)$/,
        plugins: ['@babel/plugin-transform-react-constant-elements'],
      },
    ],
    env: {
      test: {
        sourceMaps: 'both',
      },
    },
  };
}