Skip to main content

Rspack Production Configuration

The rspack.production.config.ts specializes the build for deployment, focusing on three core goals: Performance, Size, and Security.


1. Advanced Minification

In production mode, the framework applies a multi-layered minification strategy:

  • JavaScript: Utilizes SwcJsMinimizerRspackPlugin (or TerserPlugin as a fallback). It performs dead-code elimination, scope hoisting, and variable mangling.
  • CSS: Utilizes LightningCssMinimizerRspackPlugin. This is significantly more efficient than standard CSS minifiers as it understands CSS syntax deeply, allowing for advanced tree-shaking of unused styles.

2. Payload Optimization

To minimize the Time to Interactive (TTI), several asset optimizations are applied:

  • Brotli & Gzip Compression: The CompressionPlugin generates pre-compressed versions of all static files. This allows the web server (Nginx/Vercel) to serve these files instantly without on-the-fly compression overhead.
  • Tree Shaking: Enabled globally for all packages, ensuring that only the used parts of libraries (like lodash-es) are included in the final bundles.

3. Plugins Active in Production

Note that several plugins commonly associated with production output are actually configured in the base config (they are not production-only):

  • CssExtractRspackPlugin: Extracts CSS into separate files rather than inlining them into JavaScript. This is essential for cache-friendly delivery and FCP optimization. (Configured in the base config.)
  • Workbox InjectManifest: Generates a Service Worker that handles offline capabilities, caching strategies (Stale-While-Revalidate), and faster repeat visits. (Configured in the base config.)
  • Analyze Mode: If triggered via --analyze, an Rsdoctor bundle analysis is generated, allowing developers to identify and eliminate "fat" dependencies.

4. Source Map Strategy

The framework uses SourceMapDevToolPlugin (configured in the base config, not production-only) to generate external source maps (.map files). These are not served to the end user by default but are preserved for debugging production errors in tools like Sentry or Instana.