module.exports = () => {
  const { isProduction } = require("../config");

  return {
    test: /\.(js|mjs|jsx|ts|tsx)$/,
    // pass also node_modules through babel on production otherwise libraries
    // like `gsap` break on Edge and IE
    // exclude: isProduction ? /\xxxxxxxx/ : /node_modules/,
    exclude: isProduction ? /\xxxxxxxx/ : /node_modules(?!\/(@acanto)).*/,
    // exclude: isProduction ? /\xxxxxxxx/ : /node_modules(?!\/(swiper|gsap)).*/,
    use: {
      loader: require.resolve("babel-loader"),
      options: {
        presets: [
          [
            require.resolve("@babel/preset-env"),
            {
              useBuiltIns: "entry",
              corejs: "3.6",
              modules: false,
              loose: true,
            },
          ],
        ],
        plugins: [
          [require.resolve("@babel/plugin-transform-runtime")],
          [require.resolve("@babel/plugin-transform-modules-commonjs")],
          [
            require.resolve("@babel/plugin-proposal-class-properties"),
            { loose: true },
          ],
          [require.resolve("@babel/plugin-proposal-optional-chaining")],
        ],
        babelrc: false,
        configFile: false,
        cacheDirectory: true,
        cacheCompression: isProduction,
        compact: isProduction,
      },
    },
  };
};
