Skip to content

web-optim/jsmin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

169 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

jsmin logo

Jsmin

Readme | GitHub |

GitHub code size in bytes Maintenance CodeFactor Gitpod

An extremely fast JavaScript minifier (pronounced as jasmine or jazz-min /jฤƒzโ€ฒmฤญn/.) written in Rust.

Table of Contents

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.

โฌ†๏ธ Back to Top

Performance ๐Ÿ“Š

Comparison with esbuild, run on common libraries.

Work in progress! ๐Ÿ™‚.

โฌ†๏ธ Back to Top

Features ๐Ÿš€

  • ๐Ÿš€ 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, and prototype aren't used.
  • ๐Ÿงฎ Transforms if statements to expressions.

โฌ†๏ธ Back to Top

Usage ๐Ÿ› ๏ธ

Rust

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}");

Node.js

Install the dependency:

npm i @jsmin/node

Call the method:

import {minify} from "@jsmin/node";

const src = Buffer.from("let x = 1;", "utf-8");
const min = minify(src);

โฌ†๏ธ Back to Top

In Progress ๐Ÿงช

  • 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 === undefined with x == null, where x is side-effect free.
    • Replace typeof x === "undefined" with x === undefined.
    • Using shorthand properties.
    • Replace void x with x, undefined.
    • Replace return undefined with return.
    • Replace const with let.
    • Hoist let and const.
    • Unwrapping blocks.
    • Unwrapping paretheses, altering expressions as necessary.
    • if (...) return a; else if (...) return b; else return c => return (...) ? a : (...) ? b : c.

โฌ†๏ธ Back to Top

More Contributors Wanted ๐Ÿ“ฃ

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.

โฌ†๏ธ Back to Top

Supporting Jsmin ๐Ÿ’–

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.

โฌ†๏ธ Back to Top

Roadmap ๐Ÿ›ฃ๏ธ

Coming soon! ๐Ÿ™‚.

โฌ†๏ธ Back to Top

Contributing ๐Ÿ™‹

Contributions are welcome from anyone. It doesn't matter who you are; you can still contribute to the project in your own way.

Not a developer but still want to contribute?

Check out this video by Mr. Nick on how to contribute.

Developer

If you are a developer, have a look at the CONTRIBUTING.md document for more information.

โฌ†๏ธ Back to Top

License ๐Ÿ“œ

Jsmin is licensed under the APACHEv2 license.

โฌ†๏ธ Back to Top

Credits ๐Ÿค

We would like to thank the following people for their contributions and support:

Contributors



Stargazers

โฌ†๏ธ Back to Top




Thank you for Visiting

About

๐Ÿš€ Extremely fast JavaScript minifier, available for Rust and Node.js

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors 6