// eslint-disable-next-line no-process-env
const mode = process.env.WEBPACK_SERVE ? 'development' : 'production';

const config = {
  presets: [
    ['@babel/preset-env', {
      targets: "> 0.25%, not dead",
      modules: false,
      useBuiltIns: "entry",
      corejs: "3.32",
      debug: false,
      // useBuiltIns: 'usage',
      shippedProposals: true,
    }],
    ['@babel/preset-react', {
      useBuiltIns: true,
    }],
    ['@babel/typescript', {
      allExtensions: true,
      isTSX: true,
    }],
  ],
  plugins: [
    '@babel/plugin-proposal-class-properties',
    '@babel/plugin-syntax-dynamic-import',
    '@babel/proposal-object-rest-spread',
    '@babel/plugin-proposal-optional-chaining',
    'babel-plugin-typescript-to-proptypes',
    mode !== 'production' && require.resolve('react-refresh/babel'),
  ].filter(Boolean),
};

// Jest needs module transformation
config.env = {
  test: {
    presets: config.presets,
    plugins: config.plugins,
  },
};
config.env.test.presets[0][1].modules = 'auto';

module.exports = config;
