npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@minify-js/node

v0.6.0

Published

Extremely fast JavaScript minifier, written in Rust

Downloads

109

Readme

minify-js

Extremely fast JavaScript minifier, written in Rust.

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.

Performance

Comparison with esbuild, run on common libraries.

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.

Usage

CLI

Precompiled binaries are available for Linux, macOS, and Windows.

Linux x64 | macOS x64 | Windows x64

Use the --help argument for more details.

minify-js --output /path/to/output.min.js /path/to/src.js

Rust

Add the dependency:

[dependencies]
minify-js = "0.6.0"

Call the method:

use minify_js::{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 @minify-js/node

Call the method:

import {minify} from "@minify-js/node";

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

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.