"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = createRspackSsrConfig;
function _core() {
  const data = require("@rspack/core");
  _core = 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 _rspack() {
  const data = require("./rspack.common");
  _rspack = function () {
    return data;
  };
  return data;
}
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function createRspackSsrConfig(workspaceDir, entryFiles, publicDir) {
  const isEnvProductionProfile = process.argv.includes('--profile');
  return {
    stats: {
      children: true,
      errorDetails: true
    },
    mode: 'production',
    target: 'node',
    // this bundle ships inside the package, so it follows the browser config's opt-in: the `eval-*`
    // devtools inline a base64 source map per module, which was 60% of the 37 MB `ssr/index.js`.
    devtool: _rspack().shouldUseSourceMap ? 'source-map' : false,
    experiments: {
      css: true
    },
    optimization: {
      minimize: true,
      minimizer: [new (_core().rspack.SwcJsMinimizerRspackPlugin)({
        minimizerOptions: {
          compress: {
            ecma: 5,
            comparisons: false,
            inline: 2
          },
          // `keep_classnames` for the same reason as the browser build - react resolves component
          // names from the class name, and the ssr output is rendered by the same components.
          mangle: {
            safari10: true,
            keep_classnames: true
          },
          format: {
            ecma: 5,
            comments: false,
            ascii_only: true
          }
        }
      })]
    },
    entry: {
      main: entryFiles
    },
    output: {
      path: _path().default.resolve(workspaceDir, publicDir, 'ssr'),
      publicPath: '/public/ssr/',
      library: {
        type: 'commonjs'
      },
      filename: 'index.js',
      chunkFilename: 'static/js/[name].[contenthash:8].chunk.js'
    },
    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)(), (0, _rspack().fontRule)(), ...(0, _rspack().styleRules)({
        sourceMap: _rspack().shouldUseSourceMap,
        resolveUrlLoader: true,
        exportsOnly: true
      }), {
        // `cjs` must be excluded here exactly as it is in the browser config. without it a `.cjs`
        // module is emitted as an asset and its module value becomes the emitted file's url, so a
        // component imported from one renders as `<"/public/ssr/<hash>.cjs" />` and react throws
        // "Invalid tag" (#65) on every request - which the ssr middleware swallows, silently
        // falling back to the client-rendered html.
        exclude: [/\.(cjs|js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/, /\.css$/, /\.s[ac]ss$/, /\.less$/],
        type: 'asset/resource'
      }]
    },
    plugins: [new (_core().rspack.ProvidePlugin)({
      process: _webpack().fallbacksProvidePluginConfig.process
    }), new (_core().rspack.IgnorePlugin)({
      resourceRegExp: /^\.\/locale$/,
      contextRegExp: /moment$/
    })],
    performance: false
  };
}

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