minify-js
Extremely fast JavaScript minifier, written in Rust.
Currently usable, but under development, with the goal to be similar in effectiveness to common minifiers including esbuild and terser. Improvements and suggestions welcome!
Goals
- Fully written in Rust for maximum compatibility with Rust programs and derivatives (FFI, WASM, embedded, etc.).
- Maximises performance on a single CPU core for simple efficient scaling and easy compatible integration.
- Minification of individual inputs/files only; no bundling or transforming.
- Prefer minimal complexity and faster performance over maximum configurability and minimal extra compression.
Features
- Fast parsing powered by SIMD instructions and lookup tables.
- Minification of variable, parameter, and function names.
Usage
Add the dependency:
[]
= "0.0.2"
Call the method:
use BufWriter;
use minify;
let mut code: & = b"let x = 1;";
let mut out = new;
minify.unwrap;
assert_eq!;
In progress
- Combine and reorder declarations.
- Omit more semicolons, spaces, parentheses, and braces.
- Minify import and export syntax.
- More extensive testing, especially over rare syntax.
- Evaluation and folding of constant expressions.
- Parse and erase TypeScript syntax.
- FFI libraries for other languages.
- Aliasing of reused well-knowns.
- Removal of unreachable and redundant code.
- Aliasing frequently accessed properties and called methods.
- Better support for non-ASCII syntax.
- Replacing if statements with conditional and logical expressions.
- Aliasing repeated identical literal values.
- Micro-optimisations:
- Unwrap string literal computed members, then identifier or number string members.
- Replace
x === null || x === undefined
withx == null
, wherex
is side-effect free. - Using shorthand properties and Object.assign.
- (Dangerous) Replace functions without use of
this
with arrow functions. - Replace
void x
withundefined
, wherex
is side-effect free. - Replace
return undefined
withreturn
. - Replace
const
withlet
. - Hoist
let
andconst
. - Unwrapping blocks.
- Unwrapping paretheses, altering expressions as necessary.