๐งช 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 ๐
- feat(mf): runtimePlugins support pass params by @2heal1 in #11818
- feat(browser): support
modules
inBrowserRequirePlugin
by @CPunisher in #11822 - feat(mf): support lazy compilation by @2heal1 in #11779
- feat: enable lazy barrel by default by @ahabhgk in #11841
- feat: rslib supports add shims for js/esm by @JSerFeng in #11840
- feat: eval simple expression for enum member by @ahabhgk in #11859
- feat: implement
extractSourceMap
option by @colinaaa in #11814
Bug Fixes ๐
- fix(loader-runner): add missing break statements in switch cases by @chenjiahan in #11794
- fix: revert "fix: remove
serde
feature oflightningcss
(#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 ๐จ
- refactor: update type definitions to fix Rslint issues by @chenjiahan in #11798
- refactor: remove experiments.layers by @JSerFeng in #11819
- refactor: output.charset false by default by @JSerFeng in #11837
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
- test: run webpack multi compiler test cases with test tools by @LingyuCoder in #11787
- test: fix hot update loader by @LingyuCoder in #11774
- chore: rspack_plugin_esm_library should have description by @SyMind in #11789
- chore: upgrade mf runtime tools to v0.19.1 by @ahabhgk in #11788
- test: run webpack stats cases with test tools by @LingyuCoder in #11791
- chore(deps): update dependency @rslib/core to v0.15.0 by @renovate[bot] in #11748
- chore(deps): lock file maintenance by @renovate[bot] in #11783
- chore(deps): update dependency typescript to ^5.9.3 by @renovate[bot] in #11802
- chore(deps): update patch npm dependencies by @renovate[bot] in #11801
- chore(deps): update dependency memfs to v4.48.1 by @renovate[bot] in #11807
- chore(deps): update dependency zx to v8.8.4 by @renovate[bot] in #11811
- test: run webpack example cases with test tools by @LingyuCoder in #11820
- test: run webpack watch cases with test tools by @LingyuCoder in #11821
- chore(deps): update dependency @microsoft/api-extractor-model to v7.31.1 by @renovate[bot] in #11816
- chore(deps): update pnpm to v10.18.1 by @renovate[bot] in #11812
- test: skip flaky test cases by @stormslowly in #11827
- test: run webpack hot cases with test tools by @LingyuCoder in #11826
- test: add type of test config files by @LingyuCoder in #11831
- test: add missing await in basic tests by @deepcoldy in #11824
- test: align more test cases with webpack by @LingyuCoder in #11834
- chore(wasm): bump and fix @napi-rs/wasm-runtime by @CPunisher in #11836
- test: run webpack error cases with test tools by @LingyuCoder in #11839
- chore: avoid lazy compilation mf e2e flaky by @ahabhgk in #11843
- test: remove webpack tests by @LingyuCoder in #11842
- chore(deps): update patch npm dependencies by @renovate[bot] in #11806
- ci: fix lazy-compilation persistent cache e2e case by @jerrykingxyz in #11844
- chore: fix Node typeless warning when building packages by @chenjiahan in #11847
- chore: clean up TODO comments and simplify code by @chenjiahan in #11848
- test: sync webpack config test cases to rspack by @LingyuCoder in #11853
- test: inject test and rspack pathes by @LingyuCoder in #11856
- test: remove legacy builtin configuration of builtin test cases by @LingyuCoder in #11857
- chore: fix invalid lint:rs script in package.json by @chenjiahan in #11863
- test: rename all webpack config files to rspack by @LingyuCoder in #11864
- test: remove
template.md
andreadme.md
in webpack-examples by @LingyuCoder in #11865 - test: move test scripts to test tools by @LingyuCoder in #11866
- chore(swc_plugin_import): inherit workspace lint config by @chenjiahan in #11867
- test: remove legacy supports checker and test filter by @LingyuCoder in #11868
- test: use new hot update plugin to run legacy hot cases by @LingyuCoder in #11870
- chore: avoid using
BROWSER
env by @colinaaa in #11855
New Contributors
- @deepcoldy made their first contribution in #11824
Full Changelog: v1.5.8...v1.6.0-beta.0