π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
; - β
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:
({
fixCount: 1, // the more fixCount - less output size
conditions: false,
mangleClassNames: true,
mangle: true,
mergeVariables: true,
removeUnusedVariables: false,
removeConsole: false,
removeUselessSpread: true,
applyTemplateLiterals: true,
convertStrictEqualToEqual: false,
});
And usage example:
import {minify} from '@putout/minify';
const source = `
const a = 5;
const b = 6;
`;
minify(source, {
removeUnusedVariables: false,
});
MIT