Closure-Compiler is a full optimizing compiler and transpiler. It offers unmatched optimizations, provides type checking and can easily target transpilation to different versions of ECMASCRIPT.
Note: This plugin is a very early beta and currently uses a custom build of closure-compiler while neccessary changes are integrated back into the main compiler repository. Only the java version of closure-compiler is currently supported.
const ClosureCompilerPlugin = require('closure-webpack-plugin');
new ClosureCompilerPlugin({mode: 'STANDARD'}, {
// compiler flags here
//
// for debuging help, try these:
//
// formatting: 'PRETTY_PRINT'
// debug: true
})
STANDARD
(default) or AGGRESSIVE_BUNDLE
. Controls how the plugin utilizes the compiler.STANDARD
mode, closure-compiler is used as a direct replacement for other minifiers as well as most Babel transformations.AGGRESSIVE_BUNDLE
mode, the compiler performs additional optimizations of modules to produce a much smaller file, but
is not compatible with all input modules.The plugin controls certain compiler flags. The following flags should not be used in any mode:
In this mode, the compiler rewrites CommonJS modules and hoists require calls. Some modules are not compatible with this type of rewritting. In particular, hoisting will cause the following code to execute out of order:
const foo = require('foo');
addPolyfillToFoo(foo);
const bar = require('bar');
Aggressive Bundle Mode utilizes a custom runtime in which modules within a chunk file are all included in the same scope. This avoids the cost of small modules.
In Aggressive Bundle Mode, a file can only appear in a single output chunk. Use the Commons Chunk Plugin to split duplicated files into a single output chunk.
Chad Killingsworth | Joshua Wiens |