Readme |
GitHub |
An extremely fast JavaScript minifier (pronounced as jasmine or jazz-min
/jฤzโฒmฤญn/.) written in Rust.
Table of Contents
-
Getting Started
-
Overview
-
Community
- 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.
Comparison with esbuild, run on common libraries.
Work in progress! ๐.
- ๐ Fast parsing powered by SIMD instructions and lookup tables.
- ๐ Data is backed by a fast reusable bump allocation arena.
- ๎ด Supports JSX.
- ๐๏ธ Analyses scopes and variable visibilities.
- ๐ Minifies identifiers.
- โญ๏ธ Omits semicolons, spaces, parentheses, and braces where possible.
- โ๏ธ Transforms functions to arrow functions when
new,this,arguments, andprototypearen't used. - ๐งฎ Transforms
ifstatements to expressions.
Add the dependency:
[dependencies]
jsmin = "0.6"Call the method:
use jsmin::{Session, TopLevelMode, minify};
let mut code: &[u8] = b"const main = () => { let my_first_variable = 1; };";
let session = Session::new();
let mut out = Vec::new();
minify(&session, TopLevelMode::Global, code, &mut out).unwrap();
assert_eq!(out.as_slice(), b"const main=()=>{let a=1}");Install the dependency:
npm i @jsmin/nodeCall the method:
import {minify} from "@jsmin/node";
const src = Buffer.from("let x = 1;", "utf-8");
const min = minify(src);- Combine and reorder declarations.
- Evaluation and folding of constant expressions.
- Parse and erase TypeScript syntax.
- Removal of unreachable, unused, and redundant code.
- Inlining single-use declarations.
- Replacing if statements with conditional and logical expressions.
- Returning an explicit error on illegal code e.g. multiple declarations/exports with identical names.
- Much more inline, high level, and usage documentation.
- Support import and export string names e.g.
import { "a-b" as "c-d" } from "x". - Simplify pattern parsing and minification.
- Micro-optimisations:
- Unwrap string literal computed members, then identifier or number string members.
- Replace
x === null || x === undefinedwithx == null, wherexis side-effect free. - Replace
typeof x === "undefined"withx === undefined. - Using shorthand properties.
- Replace
void xwithx, undefined. - Replace
return undefinedwithreturn. - Replace
constwithlet. - Hoist
letandconst. - Unwrapping blocks.
- Unwrapping paretheses, altering expressions as necessary.
if (...) return a; else if (...) return b; else return c=>return (...) ? a : (...) ? b : c.
We are looking for more willing contributors to help grow this project. For more information on how you can contribute, check out the project board and the CONTRIBUTING.md file for guidelines and rules for making contributions.
For full details and other ways you can help out, see: Contributing
If you use Jsmin and would like to contribute to its development, we're glad to have you on board! Contributions of any size or type are always welcome, and we will always acknowledge your efforts.
Several areas that we need a bit of help with at the moment are:
- Completing the In-Progress listings: Help by completing some of the things from the in-progress listing.
- Submit a PR to add a new feature, fix a bug, update the docs, add a theme, widget, or anything else.
- Star Jsmin on GitHub.
Coming soon! ๐.
Contributions are welcome from anyone. It doesn't matter who you are; you can still contribute to the project in your own way.
Check out this video by Mr. Nick on how to contribute.
If you are a developer, have a look at the CONTRIBUTING.md document for more information.
Jsmin is licensed under the APACHEv2 license.
We would like to thank the following people for their contributions and support:
Contributors
Stargazers
