The fast, future-friendly minifier. Try before you buy at butternut.now.sh
Warning: this is alpha software. Test thoroughly before using in production! Consider using the check option. Please report any bugs you find!
The compression is better than Babili and closure-compiler-js (in standard compilation mode — you can get better results with Closure in advanced mode, but only by writing your code in a very particular way). It's almost as good as Uglify in its current version.
You can test out the different tools with
npm run bench.
Note: UglifyJS supports ES2015+ as of very recently — see uglify-es.
The traditional approach to minification is this: parse your source code into an abstract syntax tree (AST) using something like Acorn, manipulate the AST, and finally generate code from it.
Butternut takes a different approach. It uses Acorn to generate an AST, but instead of steps 2 and 3 it then edits the code in place using magic-string — which is much less costly than AST manipulation and code generation.
The easiest way to use Butternut is to plug it into your existing build process:
Install Butternut globally, then use the
npm install --global butternut # or npm i -g butternutsquash app.js > app.min.js
squash --help to see the available options.
Install Butternut to your project...
npm install --save-dev butternut # or npm i -D butternut
...then use it like so:
const butternut = ;const code map = butternut;
options argument, if supplied, is an object that can have the following properties:
|Option||CLI equivalent||Default value||Description|
||Parse output. See below|
||Whether to allow direct
||Whether to create a sourcemap. Set to
||The output filename, used in sourcemap generation|
||The source filename, used in sourcemap generation|
||Whether to include the source file in the
Since Butternut is a new project, it hasn't yet been battle-tested. It may generate code that you don't expect. If you pass
check: true (or use the
If you find bugs while using Butternut, please raise an issue!