{"id":19407,"library":"closure-webpack-plugin","title":"closure-webpack-plugin","description":"A webpack plugin integrating Google Closure Compiler and Closure Library for JavaScript optimization and transpilation. Version 2.6.1 (webpack 4 branch) requires google-closure-compiler >=20200830.0.0 and webpack 4.x. Offers three platforms (native, Java, JavaScript) and two modes (STANDARD for minification/transpilation, AGGRESSIVE_BUNDLE for advanced module hoisting and optimization). Unlike TerserPlugin or Babel, it provides full Closure Compiler optimizations including dead code elimination, type checking, and cross-module analysis. Not compatible with webpack 5.","status":"active","version":"2.6.1","language":"javascript","source_language":"en","source_url":"https://github.com/webpack-contrib/closure-webpack-plugin","tags":["javascript"],"install":[{"cmd":"npm install closure-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add closure-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add closure-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency providing the Closure Compiler binary; must be installed separately.","package":"google-closure-compiler","optional":false},{"reason":"Peer dependency; only compatible with webpack 4.x.","package":"webpack","optional":false}],"imports":[{"note":"Package does not provide a default ESM export; require() is required.","wrong":"import ClosurePlugin from 'closure-webpack-plugin';","symbol":"ClosurePlugin","correct":"const ClosurePlugin = require('closure-webpack-plugin');"},{"note":"In TypeScript, use `import = require()` for proper CommonJS interop; namespace import may fail.","wrong":"import * as ClosurePlugin from 'closure-webpack-plugin';","symbol":"ClosurePlugin","correct":"import ClosurePlugin = require('closure-webpack-plugin');"},{"note":"No default export; use named export if the package's TypeScript typings allow it (but check actual typings).","wrong":"const { default: ClosurePlugin } = require('closure-webpack-plugin');","symbol":"ClosurePlugin as ClosurePlugin","correct":"const { ClosurePlugin } = require('closure-webpack-plugin');"}],"quickstart":{"code":"const ClosurePlugin = require('closure-webpack-plugin');\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: {\n    filename: 'bundle.js',\n    path: __dirname + '/dist'\n  },\n  optimization: {\n    minimizer: [\n      new ClosurePlugin({\n        mode: 'STANDARD',\n        platform: 'javascript'\n      }, {\n        // compiler flags\n        formatting: 'PRETTY_PRINT',\n        debug: true,\n        renaming: false\n      })\n    ]\n  }\n};","lang":"javascript","description":"Basic webpack config using closure-webpack-plugin as the minifier with JavaScript platform, STANDARD mode, and debug flags."},"warnings":[{"fix":"Use webpack 4 or switch to an alternative plugin for webpack 5.","message":"Plugin only works with webpack 4.x; not compatible with webpack 5.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Remove these flags from the compiler options object. They are overridden internally.","message":"Do not set compiler flags module_resolution, output_wrapper, dependency_mode, create_source_map, module, or entry_point—they are controlled by the plugin and will conflict.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use lowercase strings as above. The plugin may also accept uppercase but it's not guaranteed.","message":"The 'platform' option accepts strings 'native', 'java', 'javascript', but old documentation used case-insensitive values.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Ensure modules with side-effects are separated into different chunks or mark them with sideEffects: false in package.json.","message":"AGGRESSIVE_BUNDLE mode hoists require() calls, which can cause out-of-order execution if polyfills or side-effects are interleaved.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set childCompilations: true or a custom function if child compilations need closure optimization.","message":"childCompilations defaults to false—plugins like html-webpack-plugin may not get optimized output.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use `const ClosurePlugin = require('closure-webpack-plugin');`","cause":"Importing the plugin incorrectly (using default import instead of require).","error":"TypeError: ClosurePlugin is not a constructor"},{"fix":"Run `npm install --save-dev google-closure-compiler`","cause":"Required peer dependency not installed.","error":"Error: Cannot find module 'google-closure-compiler'"},{"fix":"Downgrade to webpack 4.x, or use an alternative plugin (e.g., terser-webpack-plugin) for webpack 5.","cause":"Using the plugin with webpack 5.","error":"Error: webpack version 5.x is not supported"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}