esmangle-webpack-plugin

A minifier for Webpack based on ESMangle

Usage no npm install needed!

<script type="module">
  import esmangleWebpackPlugin from 'https://cdn.skypack.dev/esmangle-webpack-plugin';
</script>

README

ESMangle Webpack Plugin

NPM

A minifier for Webpack based on ESMangle.

Almost as effective as the Uglify plugin whilst significantly faster.

Use this plugin all the time so that you are developing the same code that you will deploy. Avoid surprises in production, particularly with Angular based projects.

Usage

var ESMangleWebpackPlugin = require('esmangle-webpack-plugin');
{
  plugins : [
    new ESMangleWebpackPlugin()
  ]
}

It is possible to pass options to the constructor, but this is normally not required. By default the plugin will produce a compressed output for all .js files.

How it works

Esprima parses the code into an Abstract Syntax Tree (AST). This is passed to esmangle which renames variables but does not compress the code. The AST is rendered back to Javascript by applying escodegen with options.format.

The default constructor is equivalent to the following.

new ESMangleWebpackPlugin({
    test  : /\.js($|\?)/i,
    format: {
        renumber   : true,
        hexadecimal: true,
        escapeless : true,
        compact    : true,
        semicolons : false,
        parentheses: false
    }
})