"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = createRspackBrowserConfig;
function _core() {
  const data = require("@rspack/core");
  _core = function () {
    return data;
  };
  return data;
}
function _workboxWebpackPlugin() {
  const data = _interopRequireDefault(require("workbox-webpack-plugin"));
  _workboxWebpackPlugin = function () {
    return data;
  };
  return data;
}
function _webpack() {
  const data = require("@teambit/webpack");
  _webpack = function () {
    return data;
  };
  return data;
}
function _path() {
  const data = _interopRequireDefault(require("path"));
  _path = function () {
    return data;
  };
  return data;
}
function _postcss() {
  const data = require("./postcss.config");
  _postcss = function () {
    return data;
  };
  return data;
}
function _html() {
  const data = require("./html");
  _html = function () {
    return data;
  };
  return data;
}
function _rspack() {
  const data = require("./rspack.common");
  _rspack = function () {
    return data;
  };
  return data;
}
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/*
 * Rspack production config for the bit ui (replaces webpack.browser.config.ts)
 * i.e. `bit build`, `bit start` (non-dev mode)
 */

function createRspackBrowserConfig(outputDir, entries, publicDir) {
  const isEnvProductionProfile = process.argv.includes('--profile');
  return {
    stats: {
      children: true,
      errorDetails: true
    },
    mode: 'production',
    devtool: _rspack().shouldUseSourceMap ? 'source-map' : false,
    experiments: {
      css: true
    },
    entry: Object.fromEntries(entries.map(entry => [entry.name, entry.files])),
    output: {
      path: _path().default.resolve(outputDir, publicDir),
      filename: 'static/js/[name].[contenthash:8].js',
      chunkFilename: 'static/js/[name].[contenthash:8].chunk.js',
      cssFilename: 'static/css/[name].[contenthash:8].css',
      cssChunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
      publicPath: '/'
    },
    optimization: {
      minimize: true,
      minimizer: [new (_core().rspack.SwcJsMinimizerRspackPlugin)({
        minimizerOptions: {
          compress: {
            ecma: 5,
            comparisons: false,
            inline: 2
          },
          mangle: {
            safari10: true,
            keep_classnames: true
          },
          format: {
            ecma: 5,
            comments: false,
            ascii_only: true
          }
        }
      }), new (_core().rspack.LightningCssMinimizerRspackPlugin)({})],
      splitChunks: {
        chunks: 'all',
        name: false
      },
      runtimeChunk: {
        name: entrypoint => `runtime-${entrypoint.name}`
      }
    },
    resolve: {
      extensions: _rspack().moduleFileExtensions.map(ext => `.${ext}`),
      alias: (0, _rspack().resolveAlias)({
        profile: isEnvProductionProfile
      }),
      fallback: _rspack().resolveFallback
    },
    module: {
      parser: _rspack().cssParser,
      rules: [(0, _rspack().mjsRule)(), (0, _rspack().swcRule)(), (0, _rspack().sourceMapRule)(),
      // Images
      {
        test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.svg$/],
        type: 'asset',
        parser: {
          dataUrlCondition: {
            maxSize: _rspack().imageInlineSizeLimit
          }
        }
      }, (0, _rspack().fontRule)(), ...(0, _rspack().styleRules)({
        sourceMap: _rspack().shouldUseSourceMap,
        postCssConfig: _postcss().postCssConfig,
        resolveUrlLoader: true
      }),
      // Catch-all for other assets
      {
        exclude: [/\.(cjs|js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/, /\.css$/, /\.s[ac]ss$/, /\.less$/],
        type: 'asset/resource'
      }]
    },
    plugins: [
    // one html per entry, each injecting only its own entry's chunks. `index.html` is no longer
    // emitted: with two roots in one compilation there is no single default document, so the ui
    // server falls back to `<entry>.html` for the root it is serving.
    ...entries.map(entry => new (_core().rspack.HtmlRspackPlugin)({
      filename: `${entry.name}.html`,
      chunks: [entry.name],
      inject: true,
      templateContent: (0, _html().html)(entry.title)(),
      minify: true
    })), new (_core().rspack.ProvidePlugin)({
      process: _webpack().fallbacksProvidePluginConfig.process
    }), new (_core().rspack.IgnorePlugin)({
      resourceRegExp: /^\.\/locale$/,
      contextRegExp: /moment$/
    }), new (_rspack().RspackManifestPlugin)({
      fileName: 'asset-manifest.json',
      generate: _rspack().generateAssetManifest
    }), new (_workboxWebpackPlugin().default.GenerateSW)({
      clientsClaim: true,
      maximumFileSizeToCacheInBytes: 5000000,
      exclude: [/\.map$/, /asset-manifest\.json$/],
      navigateFallback: 'public/index.html',
      navigateFallbackDenylist: [new RegExp('^/_'), new RegExp('/[^/.?]+\\.[^/]+$')]
    })],
    performance: false
  };
}

//# sourceMappingURL=rspack.browser.config.js.map