github web-infra-dev/rspack v2.0.4

7 hours ago

Highlights 💡

  • Inline const with module declarations (#14032): Previously, Rspack only inlined constant exports from leaf modules in the module graph. Now constant exports from any module can be inlined, even when that module also imports or re-exports other modules. In rare circular-reference cases this can make a TDZ error disappear, but we do not expect real projects to rely on TDZ errors, so Rspack prioritizes the optimization.

    // constants.js
    import './setup';
    
    export const ENABLE_EXPERIMENT = false;
    
    // entry.js
    import { ENABLE_EXPERIMENT } from './constants';
    
    if (ENABLE_EXPERIMENT) {
      runExperiment();
    }
    
    // Before: constants.js is not a leaf module, so the branch could keep
    // reading the imported binding.
    if (ENABLE_EXPERIMENT) {
      runExperiment();
    }
    
    // Now: the constant can still be inlined, so dead branches are easier
    // to remove.
    if (false) {
      runExperiment();
    }
  • Tree shake namespace default reexport (#13980): Previously, the import * as a from './a'; export default a; pattern did not tree-shake a through the default export. Now Rspack further analyzes the default-exported namespace object and can remove unused exports from the original namespace module.

    // a.js
    export function used() {}
    export function unused() {}
    
    // bridge.js
    import * as a from './a';
    export default a;
    
    // app.js
    import a from './bridge';
    
    a.used();
    
    // Before: both used and unused could be kept in the bundle.
    // Now: unused can be tree-shaken.
  • CSS global module type (#13988): css/global is useful when most selectors in a stylesheet should stay global, but you still want CSS Modules features for selected local selectors. This makes it easier to migrate existing global CSS gradually without turning every class name into a local scoped name.

    export default {
      module: {
        rules: [{ test: /\.global\.css$/i, type: 'css/global' }],
      },
    };
    /* style.global.css */
    .button {
      color: red;
    }
    
    :local(.title) {
      font-weight: 600;
    }

    .button stays global, while .title is renamed as a local class.

  • CSS Modules local ident options (#14009): CSS Modules now support local ident hash options such as hash function, digest, digest length, and salt. These options make generated class names more configurable and better aligned with webpack-compatible CSS Modules setups.

    export default {
      module: {
        rules: [{ test: /\.module\.css$/i, type: 'css/module' }],
        generator: {
          'css/module': {
            localIdentName: '[name]__[local]__[hash]',
            localIdentHashFunction: 'xxhash64',
            localIdentHashDigest: 'hex',
            localIdentHashDigestLength: 8,
            localIdentHashSalt: 'my-salt',
          },
        },
      },
    };

What's Changed

New Features 🎉

Performance 🚀

Bug Fixes 🐞

  • fix(rsc): skip client entry mismatch without injections by @SyMind in #14018
  • fix(cli): write logger trace output to file by default by @hardfist in #14022
  • fix(ci): repair broken rustup shim chain on macos-latest by @stormslowly in #14040
  • fix(stats): preserve sub-millisecond precision in logger time entries by @stormslowly in #14049
  • fix: import.meta.filename/dirname escape on windows by @ahabhgk in #14050
  • fix(rsc): group client chunks by server-entry ownership by @SyMind in #13880
  • fix(rslib): emit type-only isolated dts dependencies by @Timeless0911 in #14037
  • fix(copy-plugin): support JS input file system for glob copies by @intellild in #14023
  • fix: keep buildHttp imports bundled for node target by @SyMind in #14086

Document 📖

Other Changes

Full Changelog: v2.0.3...v2.0.4

Don't miss a new rspack release

NewReleases is sending notifications on new releases.