Oxc Minify is a JavaScript minifier built in Rust, providing a Node.js API for synchronous and asynchronous code minification. Currently at version 0.126.0, it is under active and rapid development, with frequent releases often introducing breaking changes as the project matures. It is designed for high performance, already outperforming `esbuild` in some benchmarks, and aims to eventually include advanced minification techniques like constant inlining and dead code removal. A key differentiator is its Rust-based architecture, offering potential speed advantages over JavaScript-based minifiers like Terser or UglifyJS. However, it is explicitly alpha software, making assumptions about semantically correct input and using a fast parsing mode that skips some semantic error checks to maximize performance.
npm install oxc-minifyVerified import paths — ran on the pinned version, not inferred.
This example demonstrates both synchronous and asynchronous minification of a JavaScript code string, showcasing common options for compression, mangling, and code generation, along with sourcemap generation.
Review your Rust FFI bindings or custom allocator usage to align with the new method names in `oxc_allocator`.
Update any code relying on `oxc_str` or `oxc_span` string type re-exports according to the new API and macro usage.
Thoroughly test minified output in your target environment. Monitor the Oxc project's GitHub releases for updates on feature completeness and stability. Avoid using in production without extensive validation.
Ensure your input code is syntactically and semantically valid before passing it to `oxc-minify`. Use linters or other parsers (e.g., `oxc-parser` in full mode) for prior validation if semantic correctness is not guaranteed.
Adjust any direct Rust-level integrations to align with the revised module structure and exports.
Always provide a string for the `filename` argument, even if it's a placeholder like `'input.js'`.
Ensure the input `sourceText` is valid JavaScript/TypeScript. `oxc-minify` expects semantically correct code and may not gracefully handle all malformed inputs.
Wrap your minification call in a `try...catch` block for `minifySync` or use `.catch()` for `minify` to handle potential errors during the minification process.