rollup-plugin-closure-compiler-js

raw JSON →
1.0.6 verified Mon Apr 27 auth: no javascript deprecated

Rollup plugin that invokes google-closure-compiler-js to optimize bundled JavaScript. Current stable version is 1.0.6, last released in 2017. The plugin wraps the deprecated google-closure-compiler-js (Java-based via Node) but users should note that google-closure-compiler-js itself was discontinued in 2018 in favor of google-closure-compiler (which uses the Java compiler natively). Key differentiators: simple Rollup integration, passes flags directly to the compiler. However, it is considered deprecated because the underlying closure-compiler-js package is no longer maintained.

error Cannot find module 'google-closure-compiler-js'
cause The underlying compiler package is deprecated and may not be installable from npm.
fix
Install an archived version: npm install google-closure-compiler-js@20180219.0.0 --save-dev
error TypeError: closure is not a function
cause Using named import instead of default import (i.e., import { closure } instead of import closure).
fix
Use default import: import closure from 'rollup-plugin-closure-compiler-js'
error Error: Invalid compilation level: ADVANCED
cause Option values must match exact string expected by closure-compiler-js.
fix
Use valid levels: 'SIMPLE', 'ADVANCED', or 'WHITESPACE_ONLY'.
deprecated rollup-plugin-closure-compiler-js is no longer actively maintained and relies on deprecated google-closure-compiler-js.
fix Use @rollup/plugin-terser or rollup-plugin-esbuild for minification, or switch to the newer google-closure-compiler package with its own rollup plugin.
breaking google-closure-compiler-js was removed from npm in 2018; install will fail unless using a cached version.
fix Pin version or switch to alternative minification plugins.
gotcha The plugin expects a default export from 'google-closure-compiler-js' but that package is discontinued.
fix Ensure you have an older version of google-closure-compiler-js in node_modules (e.g., 20180219.0.0).
gotcha Options passed to closure() are directly forwarded to ClosureCompiler.compile() - must match that API exactly.
fix Refer to google-closure-compiler-js documentation (archived) for valid flags.
breaking Rollup API changed from entry/plugins to input/plugins in v1.0; this plugin may not work with latest Rollup.
fix Use Rollup <1.0 or ensure the plugin adapts; consider using a newer plugin.
npm install rollup-plugin-closure-compiler-js
yarn add rollup-plugin-closure-compiler-js
pnpm add rollup-plugin-closure-compiler-js

Basic Rollup build that minifies the bundle using closure-compiler-js with simple optimizations.

import { rollup } from 'rollup';
import closure from 'rollup-plugin-closure-compiler-js';

async function build() {
  const bundle = await rollup({
    input: 'src/index.js',
    plugins: [
      closure({
        compilationLevel: 'SIMPLE',
        languageIn: 'ECMASCRIPT6',
        languageOut: 'ECMASCRIPT5'
      })
    ]
  });
  await bundle.write({
    file: 'dist/bundle.js',
    format: 'iife',
    name: 'MyLib'
  });
}

build().catch(err => console.error(err));