Snowpack Closure Compiler Plugin

raw JSON →
1.3.2 verified Fri May 01 auth: no javascript maintenance

Snowpack plugin (v1.3.2) that processes JavaScript assets through Google Closure Compiler for minification and static analysis. Requires Node >=8 and Snowpack >=2.0.0. Supports BUNDLE, WHITESPACE_ONLY, SIMPLE, ADVANCED compilation levels, ECMAScript version control via languageIn/languageOut, and custom output file name. Not under active development; last release in 2020.

error Error: Cannot find module 'google-closure-compiler'
cause Missing required peer dependency google-closure-compiler.
fix
npm install --save-dev google-closure-compiler
error SyntaxError: Unexpected token 'export'
cause Snowpack config uses ES module syntax but plugin expects CommonJS.
fix
Use module.exports = { ... } instead of export default.
error The "path" argument must be of type string. Received undefined
cause outputFile option not provided or set to undefined when bundle: true.
fix
Set outputFile to a string (e.g., 'main.js') in plugin options.
error Plugin load error: snowpack-plugin-closure-compiler is not a plugin function
cause Plugin imported incorrectly (e.g., using ES import or require with .default).
fix
Use the string reference in plugins array: 'snowpack-plugin-closure-compiler'.
deprecated Snowpack itself is deprecated; consider migrating to Vite.
fix Replace Snowpack with Vite and use a corresponding Vite Closure Compiler plugin (e.g., vite-plugin-closure-compiler).
breaking The plugin assumes Snowpack v2 configuration format. Snowpack v3 changed the plugin API.
fix Use with Snowpack v2 only; for v3, check compatibility or switch to another minification plugin.
gotcha If bundle: true, Closure Compiler merges all JS into one file; you must set outputFile to a single value. Multiple output files are not supported.
fix Set bundle: false if you need separate output files per input.
gotcha google-closure-compiler is a heavy dependency (Java-based). Install time and build time may increase significantly.
fix Consider using lighter minifiers like terser or esbuild for faster builds.
deprecated The plugin has not been updated since 2020; languageIn/languageOut options may not support newer ECMAScript features.
fix Use a maintained alternative or update the underlying google-closure-compiler version manually.
npm install snowpack-plugin-closure-compiler
yarn add snowpack-plugin-closure-compiler
pnpm add snowpack-plugin-closure-compiler

Configures Snowpack to run Closure Compiler with advanced optimization on all JS files, outputting a single bundle.js.

// Install: npm install --save-dev snowpack snowpack-plugin-closure-compiler google-closure-compiler
// snowpack.config.js
module.exports = {
  mount: {
    src: { url: '/dist' },
    public: { url: '/', static: true },
  },
  plugins: [
    ['snowpack-plugin-closure-compiler', {
      compilationLevel: 'ADVANCED',
      outputFile: 'bundle.js',
      bundle: true,
      languageIn: 'ECMASCRIPT_2020',
      languageOut: 'ECMASCRIPT5',
    }],
  ],
};