4.0.0 • Published 5 years ago

@semibold/closure-compiler-plugin v4.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Closure-Compiler-Plugin

Changelog

Installation

npm i -D @semibold/closure-compiler-plugin

Requirements

While there's JavaScript version of Closure Compiler, the original compiler is written in Java and thus Java version is more complete and performs better in terms of JavaScript code optimizations and compilation speed. If you want to use Java-based compiler, make sure you have installed Java SDK.

Usage

Options

compiler: <Object>

A hash of options to pass to google-closure-compiler(Flags and Options).

You can optionally specify a path to your own version of the compiler.jar if the version provided by the plugin isn't working for you. See example below for optional parameter.

jsCompiler: <Boolean>

Use pure JavaScript version of Closure Compiler (no Java dependency). Note that compilation time will be around 2x slower. Default is false.

concurrency: <Number>

The maximum number of compiler instances to run in parallel, defaults to 1.

test: <RegExp | RegExp[]>

Process only files which filename satisfies specified RegExp, defaults to /\.js($|\?)/i.

Example

const path = require("path");
const ClosureCompilerPlugin = require("@semibold/closure-compiler-plugin");

module.exports = {
    entry: path.join(__dirname, "app.js"),
    output: {
        path: path.join(__dirname, "dist"),
        filename: "[name].min.js",
    },
    mode: "production",
    devtool: "source-map",
    plugins: [
        new ClosureCompilerPlugin({
            compiler: {
                jar: "path/to/your/custom/compiler.jar", // Optional
                language_in: "ECMASCRIPT6",
                language_out: "ECMASCRIPT5",
                compilation_level: "ADVANCED",
                isolation_mode: "IIFE",
                create_source_map: true,
                externs: [path.join(__dirname, "externs.js")],
            },
        }),
    ],
    optimization: {
        minimize: false,
    },
};

FAQ