1156 releases (192 breaking)

new 0.193.0 Apr 24, 2024
0.192.19 Mar 26, 2024
0.190.8 Dec 29, 2023
0.189.73 Nov 29, 2023
0.16.1 Jul 31, 2021

#1317 in Web programming

Download history 4063/week @ 2024-01-03 3574/week @ 2024-01-10 3272/week @ 2024-01-17 5003/week @ 2024-01-24 2780/week @ 2024-01-31 2426/week @ 2024-02-07 2489/week @ 2024-02-14 2984/week @ 2024-02-21 3526/week @ 2024-02-28 3929/week @ 2024-03-06 3602/week @ 2024-03-13 2942/week @ 2024-03-20 2844/week @ 2024-03-27 4030/week @ 2024-04-03 3530/week @ 2024-04-10 2488/week @ 2024-04-17

13,390 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

~11–21MB
~302K SLoC