github web-infra-dev/rspack v1.6.0-beta.0

17 hours ago

๐Ÿงช Enhanced ESM library output (experimental)

Rspack now provides a new ESM library output that is cleaner, statically analyzable, and supports custom chunk splitting.

This new output format is fully independent of the existing chunk loading logic โ€” each chunk can be used in isolation, and all exports are placed at the top level instead of being wrapped inside the __webpack_modules__ closure.

  • Before:
exports.modules = { 
  "src/async-module.js": function(exports) {
    __webpack_require__.d(exports, {
      foo: () => foo
    })
    const foo = 42
  }
}
  • After:
// src/async-module.js
const foo = 42

export { foo }

If you'd like to try this now, follow this example:

import { rspack } from "@rspack/core";

export default{
  entry: "./index.js",
  output: {
    chunkFormat: false,  // required, EsmLibraryPlugin handles how chunk renders 
    chunkLoading: 'import',  // required, using es module dynamic import syntax to load other chunks
  },
  optimization: {
    runtimeChunk: true,  // recommended if you have async chunks
    concatenateModules: false,  // required, EsmLibraryPlugin handles scope hoisting
  },
  plugins: [new rspack.experiments.EsmLibraryPlugin()],
};

We'll make this out-of-box in Rslib soon.

See EsmLibraryPlugin for more.

๐ŸŽฏ Layers is now stable

The layer feature is now enabled by default - you no longer need to enable it manually using the experiments.layer option.

Layers is a feature that helps you group certain modules and their dependencies, allowing you to bundle them using different transforms.

For example, you can generate both ES5 and ES2015 outputs in one compilation by assigning different layers to different entries with the following configuration:

export default {
  entry: {
    legacy: {
      import: "./index.js",
      layer: "es5",
    },
    modern: {
      import: "./index.js",
      layer: "es6",
    },
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        oneOf: [
          {
            issuerLayer: "es5",
            use: [
              {
                loader: "builtin:swc-loader",
                options: {
                  jsc: {
                    target: "es5",
                    // ...
                  },
                },
              },
            ],
          },
          {
            issuerLayer: "es6",
            use: [
              {
                loader: "builtin:swc-loader",
                options: {
                  jsc: {
                    target: "es2015",
                    // ...
                  },
                },
              },
            ]
          },
        ],
      },
    ],
  },
};

๐Ÿ“„ Extract existing source maps

Rspack now supports extracting existing source map data from files (from their //# sourceMappingURL comment) via Rule.extractSourceMap. This feature is particularly useful for preserving source maps provided by third-party libraries, ensuring that debugging information remains accurate even when those libraries are bundled or transformed.

It was originally introduced in webpack v5.102.0
as a built-in replacement for the source-map-loader plugin, offering better performance and tighter integration with the build process.

export default {
  // ...
  module: {
    rules: [
      {
        test: /\.m?js$/,
        extractSourceMap: true,
      },
    ],
  },
};

โœ… Lazy barrel enabled by default

Since Rspack v1.5 introduced experimental barrel file optimization, it has been enabled by default in Rsbuild to collect early feedback.

After extensive usage and validation within Rsbuild, we now consider lazyBarrel stable, and it is enabled by default in Rspack as well.

What's Changed

Performance Improvements โšก

  • perf(browser): minor performance optimization for @rspack/browser by @CPunisher in #11795
  • perf(swc_plugin_import): replace handlebars with custom template engine by @chenjiahan in #11852

New Features ๐ŸŽ‰

Bug Fixes ๐Ÿž

  • fix(loader-runner): add missing break statements in switch cases by @chenjiahan in #11794
  • fix: revert "fix: remove serde feature of lightningcss (#11706)" by @colinaaa in #11796
  • fix: correct stats.color type to include fine-grained options by @chenjiahan in #11797
  • fix: export interop default symbol and ensure import required chunks by @JSerFeng in #11793
  • fix: should re-export real exportInfo when export dynamic js by @JSerFeng in #11776
  • fix: should process runtime chunk after normal chunks of same chunk group by @LingyuCoder in #11778
  • fix: should use external source as name hint by @JSerFeng in #11825
  • fix(swc_plugin_import): fix panic and optimize diagnostic logs by @chenjiahan in #11862
  • fix: distinguish external modules when there are import attributes by @fi3ework in #11845
  • fix: should render default exports for cjs entry and json entry by @JSerFeng in #11860

Refactor ๐Ÿ”จ

Document Updates ๐Ÿ“–

  • docs: improve documentation for stats properties by @chenjiahan in #11792
  • docs: explain how resolve.alias affects package resolution by @SyMind in #11799
  • docs(browser): add usage of useInputFileSystem to "In-Memory File system" section by @CPunisher in #11833
  • docs(browser): Add compatibility with resolve.alias description for BrowserHttpImportEsmPlugin by @CPunisher in #11838

Other Changes

New Contributors

Full Changelog: v1.5.8...v1.6.0-beta.0

Don't miss a new rspack release

NewReleases is sending notifications on new releases.