next.js
398bb42d - Mangle exported names for smaller bundle sizes

Commit
75 days ago
Mangle exported names for smaller bundle sizes This PR implements export name mangling to reduce JavaScript bundle sizes. By shortening exported variable names (e.g., `veryLongExportName` → `a`), we can achieve meaningful size savings, especially for modules with many or long-named exports. The approach leverages the existing locals/facade module split: 1. **Locals module**: Contains the actual code with mangled export names. Export names are shortened to short identifiers (a, b, c, etc.) using deterministic hashing to ensure stability across builds. 2. **Facade module**: Preserves original export names for CommonJS require and namespace imports (`import * as ns`). Maps original names to the mangled names from the locals module. Key changes: - Added `mangled_names: Option<BTreeMap<RcStr, RcStr>>` to `EsmExports` to store original→mangled name mappings - Locals module computes mangled names using `shorten_to_unique_hashes` - Import references resolve mangled names from target module's exports - Export code generation uses mangled names when available - Added `shorten_to_unique_hashes` to turbo-tasks-hash for generating short, unique JavaScript-safe identifiers - Added `mangledName` property to `__webpack_exports_info__` for debugging Note: Mangling is currently enabled only for modules that have star exports (re-exports), as these are the modules that get split into locals+facade. - Added execution tests for export name shortening and re-export chain mangling - All 208 execution tests and 85 snapshot tests pass - Next.js e2e tests pass
Author
Committer
Parents
Loading