1150 releases (191 breaking)

new 0.192.18 Mar 19, 2024
0.192.10 Feb 26, 2024
0.190.8 Dec 29, 2023
0.189.73 Nov 29, 2023
0.16.1 Jul 31, 2021

#8 in #minify

Download history 5689/week @ 2023-11-27 4171/week @ 2023-12-04 3488/week @ 2023-12-11 2513/week @ 2023-12-18 1933/week @ 2023-12-25 3553/week @ 2024-01-01 3989/week @ 2024-01-08 3067/week @ 2024-01-15 5125/week @ 2024-01-22 3084/week @ 2024-01-29 2486/week @ 2024-02-05 2164/week @ 2024-02-12 3068/week @ 2024-02-19 3267/week @ 2024-02-26 3949/week @ 2024-03-04 1447/week @ 2024-03-11

11,913 downloads per month
Used in 59 crates (14 directly)

Apache-2.0

3.5MB
93K SLoC

Minifier

EcmaScript minifier for the SWC project. This is basically a port of terser.

Note

Currently name mangler is very simple. To focus on creating a MVP, I (kdy1) will use simple logic for name mangler and implement the content-aware name mangler after publishing first non-beta version.

Debugging tips

If the output contains variables named e, t, n it typically means the original library is published in a minified form and the input contains eval. The current swc name mangler does not do anything if eval is used.

Profiling the minifier

From mac os x, run

./scripts/instrument/all.sh path/to/input/dir

lib.rs:

JavaScript minifier implemented in rust.

Assumptions

Like other minification tools, swc minifier assumes some things about the input code.

  • TDZ violation does not exist.

In other words, TDZ violation will be ignored.

  • Acesssing top-level identifiers do not have side effects.

If you declare a variable on globalThis using a getter with side-effects, swc minifier will break it.

Debugging

In debug build, if you set an environment variable SWC_CHECK to 1, the minifier will check the validity of the syntax using node --check

Cargo features

debug

If you enable this cargo feature and set the environment variable named SWC_RUN to 1, the minifier will validate the code using node before each step.

Dependencies

~10–20MB
~274K SLoC