๐Putout-based JavaScript minifier.
npm i @putout/minify
Here is list of supported ๐Putout transformations:
- โ
apply-template-literals
; - โ
apply-optional-chaining
; - โ
conditions
; - โ
convert-to-arrow-function
; - โ
convert-arguments-to-rest
; - โ
declare
; - โ
extract-sequence-expressions
; - โ
for-of
; - โ
logical-expressions
; - โ
merge-duplicate-functions
; - โ
merge-duplicate-imports
; - โ
merge-destructuring-properties
; - โ
minify
; - โ
new
; - โ
regexp
; - โ
reuse-duplicate-init
; - โ
remove-empty
; - โ
remove-nested-blocks
; - โ
remove-unused-variables
; - โ
remove-unused-expressions
; - โ
remove-unreferenced-variables
; - โ
remove-useless-arguments
; - โ
remove-useless-else
; - โ
remove-useless-return
; - โ
remove-useless-spread
; - โ
remove-useless-variables
; - โ
remove-console
; - โ
remove-debugger
; - โ
remove-unreachable-code
; - โ
simplify-ternary
; - โ
types
;
import {minify} from '@putout/minify';
minify(`
const a = 5;
const b = 6;
fn(a, b);
`);
// returns
var a=5,b=6;fn(a,b);
You can also pass options to minify
. Here is list of default options:
({
mangleClassNames: true,
mangle: true,
removeUnusedVariables: true,
removeConsole: false,
removeUselessSpread: true,
applyTemplateLiterals: true,
});
And usage example:
import {minify} from '@putout/minify';
const source = `
const a = 5;
const b = 6;
`;
minify(source, {
removeUnusedVariables: true,
});
How it's compared to Terser?
For such code:
- ๐ฅ
@putout/minify
:473B
- โ
terser
:482B
react.js
:
- ๐ฅ
@putout/minify
:16309B
- โ
terser
:16346B
MIT