grunt-closure-compiler
raw JSON → 0.0.21 verified Fri May 01 auth: no javascript maintenance
A Grunt task for Google Closure Compiler, a JavaScript minifier and optimizer. The latest version is 0.0.21, but the package appears to be stale with no recent updates. It wraps the Closure Compiler JAR file, requiring manual download of the compiler. Compared to alternative Grunt plugins like grunt-contrib-uglify, this offers access to Closure Compiler's advanced optimizations. Users must handle Java dependency, set up environment variables, and manage report files. The package is limited in features and lacks modern ES module support.
Common errors
error maxBuffer exceeded ↓
cause Closure Compiler output exceeds default buffer size (~200KB)
fix
Set 'maxBuffer' property in task config to a larger value in KB (e.g., 500)
error FATAL ERROR: JAVA not found ↓
cause Java Runtime is not installed or not in PATH
fix
Install Java (JRE) and ensure 'java' command is available
error Error: Could not find or load main class com.google.javascript.jscomp.CommandLineRunner ↓
cause closurePath is pointing to the JAR file instead of its directory, or the JAR is missing
fix
Set 'closurePath' to the directory containing compiler.jar, not the JAR itself
Warnings
breaking Requires Java Runtime to be installed and accessible ↓
fix Install Java (JRE) and ensure 'java' is in PATH
breaking Closure Compiler JAR must be manually downloaded; no npm dependency ↓
fix Download compiler.jar from https://dl.google.com/closure-compiler/compiler-latest.zip and set 'closurePath' or CLOSURE_PATH environment variable
deprecated Grunt 0.4+ compatibility issues; not updated for Grunt 1.x ↓
fix Use grunt-contrib-uglify or grunt-closure-compiler v0.0.21 with Grunt 0.4, or migrate to modern bundlers
gotcha maxBuffer property uses kilobytes, not bytes ↓
fix Set maxBuffer to desired size in KB (e.g., 500 for 500KB)
gotcha Output file is overwritten without warning if it exists ↓
fix Ensure jsOutputFile path does not accidentally overwrite important files
Install
npm install grunt-closure-compiler yarn add grunt-closure-compiler pnpm add grunt-closure-compiler Imports
- closure-compiler task wrong
require('grunt-closure-compiler');correctgrunt.loadNpmTasks('grunt-closure-compiler'); - Task configuration wrong
grunt.initConfig({ closureCompiler: { ... } });correctgrunt.initConfig({ 'closure-compiler': { ... } }); - Closure Path wrong
closurePath: '/path/to/closure-compiler/compiler.jar'correctclosurePath: '/path/to/closure-compiler'
Quickstart
// Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
'closure-compiler': {
frontend: {
closurePath: process.env.CLOSURE_PATH || '/path/to/closure-compiler',
js: 'src/input.js',
jsOutputFile: 'build/output.min.js',
maxBuffer: 500,
options: {
compilation_level: 'ADVANCED_OPTIMIZATIONS'
}
}
}
});
grunt.loadNpmTasks('grunt-closure-compiler');
grunt.registerTask('default', ['closure-compiler']);
};