### 💥 BREAKING CHANGES -365274epackages/codegen: [**BREAKING**] `printSync` return an object (#25720) (overlookmotel) ### 🚀 Features -6a7eb60packages/codegen: Alter capitalization of `sourceFilename` option (#25854) (overlookmotel) -300763fpackages/codegen: Add full source map support (#25585) (camc314) -a169e4anapi/minify: Expose property name mangling options (#24741) (Dunqing) -2f5cdb1minifier: Add property name mangling (#24740) (Dunqing) -4922141mangler: Deduplicate private accessor names (#25601) (camc314) -1c4f519napi: Add Relay transform plugin (#25503) (Boshen) -a4478e9codegen: Add `oxc-codegen` package (#25488) (overlookmotel) ### 🐛 Bug Fixes -0fbcf64codegen: Validate sourcemap options (#25860) (camc314) -345f981react_compiler: Skip node_modules by default (#25859) (Boshen) -ab81f3fminifier: Drop side-effect-free additions (#25639) (Dunqing) -241c559napi/minify: Accept RegExp for property filters (#25827) (Dunqing) -4cc7ea4codegen: Reject invalid indent options (#25807) (camc314) -53f9295isolated-declarations: Preserve undefined for defaulted any (#25292) (camc314) -8ab883acodegen: Preserve property key annotations (#25766) (Dunqing) -b13fd48minifier: Model uninitialized module vars as undefined (#25497) (Dunqing) -f6000acecmascript: Fold `**` with `Number::exponentiate`, not IEEE `pow` (#25644) (Kotaro Chikuba) -b846abcisolated-declarations: Handle ambient expando properties (#25655) (camc314) -dec0a86react-compiler: Standardize diagnostics (#25702) (Boshen) -fca2e0cparser: Reject initialized lexical declarations in for-in (#25700) (Boshen) -ae9be8fparser: Forbid type parameters on quoted constructors (#25696) (Boshen) -c5f188areact-compiler: Use Babel v1 validation defaults (#25676) (Boshen) -db44651napi: Disable reuseWorker in browser bindings (#25640) (leaysgur) -ce35d47react_compiler: Preserve JSX import source pragmas (#25592) (Boshen) -059784dsemantic: Respect shadowed `Infinity` and `NaN` in enum evaluation (#25604) (camc314) -bb5a232minifier: Keep variable declaration initilized with class when keepNames is enabled (#25584) (sapphi-red) -f49229dminifier: Keep side effects when rotating bitwise operands (#25596) (Kotaro Chikuba) -e82495becmascript: Derive `ToNumber` of `!x` from `ToBoolean` (#25595) (Kotaro Chikuba) -509931bsemantic: Classify global references per identifier (#25608) (camc314) -80484cemangler: Correct base54 safety comment (#25606) (camc314) -c1369a7codegen: Resolve private names in class heritage (#25588) (camc314) -c002f29codegen: Escape sources for empty import specifiers (#25586) (camc314) -0c68b7festree: Emit `decorators` on `FormalParameterRest` (#25582) (camc314) -cdf1846semantic: Allow legacy escapes in JSX attributes (#25576) (Boshen) -e75e102minifier: Preserve block statement in labeled iteration statements (#25162) (Armano) -771d79amangler: Exclude non-manglable symbols from slot assignment (#25539) (sapphi-red) -76b19f5minifier: Avoid duplicating large folded strings (#25532) (Dunqing) -59e8895codegen: Validate starting indent level (#25550) (camc314) -88b34f2clippy: Remove unneeded `unsafe` (#25551) (camc314) -23a7ad0parser: Stop delimited lists at end of file (#25542) (Boshen) -73acba9parser: Preserve fatal errors during await reparse (#25541) (Boshen) -c3e99d1minifier: Avoid invalid octal escapes in template folds (#25495) (Dunqing) -b4e6a9ecodegen: Output newline after `export default interface` (#25487) (overlookmotel) -5fcf683minifier: Correct issue with try finally termination (#25185) (Armano) -1645d93react_compiler: Preserve source spans (#25462) (Boshen) -8d7f9cfreact_compiler: Honor eslint suppressions (#25394) (Boshen) ### ⚡ Performance -568203eecmascript: Use binary search for known globals (#25817) (Boshen) -c84ede3estree_tokens: Share JS token update entry point (#25826) (Boshen) - 9a6e862 minifier: Move owned statements directly (#25835) (Dunqing) -61b2aefminifier: Move owned AST nodes directly (#25837) (Dunqing) -673b04bminifier: Replace expressions without take_in dummies (#25836) (Dunqing) -63ff8eflinter: Outline diagnostic construction (#25762) (Boshen) -621808ediagnostics: Measure graphemes lazily (#25723) (Boshen) -f62ed0ediagnostics: Optimize graphical number rendering (#25715) (Boshen) -7152834diagnostics: Reduce graphical formatting overhead (#25714) (Boshen) -10fc4b7diagnostics: Reduce graphical rendering allocations (#25711) (Boshen) -9c8ababdiagnostics: Batch graphical reports (#25710) (Boshen) -757f3d4mangler: Share allocated names across reused slots (#25605) (camc314) -5444cbfcodegen: Skip escaping harmless `<` tokens (#25564) (camc314) ### 📚 Documentation -58f7ab9packages/codegen: Reformat docs and comments (#25848) (overlookmotel) -627466etransform-react: Document all options (#25800) (Boshen) -ce03ac1packages/codegen: Fix JSDoc comments for `printSync` (#25722) (overlookmotel) -386a699packages/codegen: Correct JSDoc comment (#25716) (overlookmotel) -31e571dmangler: Update code example (#25599) (camc314) -fd62354codegen: Revamp package readme (#25560) (camc314) -ffa3153codegen: Clarify raw transfer Node requirement (#25565) (camc314) -c5d4063codegen: Clarify binary walk allocations (#25562) (camc314) -5703d7acodegen: Correct stale printer comments (#25561) (camc314) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Oxc Minify
See usage instructions.
This is alpha software and may yield incorrect results, feel free to submit a bug report.
Performance and Compression Size
See minification-benchmarks for details.
The current version already outperforms esbuild,
but it still lacks a few key minification techniques
such as constant inlining and dead code removal,
which we plan to implement next.
Caveats
To maximize performance, oxc-minify assumes the input code is semantically correct.
It uses oxc-parser's fast mode to parse the input code,
which does not check for semantic errors related to symbols and scopes.
API
Functions
// Synchronous minification
minifySync(
filename: string,
sourceText: string,
options?: MinifyOptions,
): MinifyResult
// Asynchronous minification
minify(
filename: string,
sourceText: string,
options?: MinifyOptions,
): Promise<MinifyResult>
Use minifySync for synchronous minification. Use minify for asynchronous minification, which can be beneficial in I/O-bound or concurrent scenarios, though it adds async overhead.
Example
import { minifySync } from "oxc-minify";
const filename = "test.js";
const code = "const x = 'a' + 'b'; console.log(x);";
const options = {
compress: {
target: "esnext",
},
mangle: {
toplevel: false,
},
codegen: {
removeWhitespace: true,
},
sourcemap: true,
};
const result = minifySync(filename, code, options);
// Or use async version: const result = await minify(filename, code, options);
console.log(result.code);
console.log(result.map);
Property-name mangling
Property mangling is opt-in and independent from identifier mangling. include is a JavaScript
RegExp and is required when mangleProps is present. Its source and flags are compiled with
Rust's regex engine. Flags i, m, s, and u are
supported. Other JavaScript flags and unsupported syntax are reported in errors.
const result = minifySync("component.js", source, {
mangle: false,
mangleProps: {
include: /^_/,
exclude: /^__public/,
reserved: ["_externalApi"],
quoted: false,
cache: previousResult?.mangleCache,
},
});
saveCache(result.mangleCache);
The returned mangleCache contains the input cache plus newly assigned names when parsing
finishes without errors, sorted by original name. A false cache value keeps that property
unchanged. Feeding the cache back keeps recorded mappings stable for later unminified input, but
the cache does not discover unchanged names that exist only in another input. Callers coordinating
separate files must pin or reserve those names explicitly. Property mappings are
single-application: do not minify already-mangled output with the same cache. Custom target names
may be shared deliberately, but must be valid JavaScript IdentifierName values and cannot be
__proto__, constructor, or prototype. The original name __proto__ is always reserved and
cannot be used as a cache key.
With quoted: false, quoting is handled per occurrence: obj._field is eligible while
obj["_field"] is not. Property mangling assumes matching properties are never accessed through
arbitrary dynamic strings. Use /* @__KEY__ */ "_field" for a string that semantically names a
property, such as a reflective API argument. Names reached through direct eval, the Function
constructor, or with must be reserved or excluded explicitly.
Properties owned by unminified code, imported module namespaces, globals, DOM objects, or other host APIs must also be excluded or reserved.
Assumptions
oxc-minify makes some assumptions about the source code.
See https://github.com/oxc-project/oxc/blob/main/crates/oxc_minifier/README.md#assumptions for details.
Supports WASM
See https://stackblitz.com/edit/oxc-minify for usage example.