Registry / web-framework / grunt-closure-tools

grunt-closure-tools

JSON →
library1.0.0jsnpmunverified

Grunt plugin integrating Google Closure Library tools (Compiler, Builder, DepsWriter) for JavaScript minification, dependency calculation, and bundling. Version 1.0.0 (stable, last release 2019) targets Grunt 0.4.x. Supports Closure Compiler jar-based compilation, closurebuilder.py concatenation, and depswriter.py deps generation. Key differentiators: full Closure toolchain integration in Grunt, support for advanced compilation options, and file-level change detection (checkModified). Alternative to gulp-closure-compiler or webpack closure plugins.

npm install grunt-closure-tools
INSTALL
IMPORT
SIG · GRUNT-CLOSURE-TOOL
G
grunt-closure-tools
web-frameworkjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (task registration)
grunt.loadNpmTasks('grunt-closure-tools');
require('grunt-closure-tools');
Do not require the module directly; use grunt.loadNpmTasks to register all three multitasks (closureCompiler, closureBuilder, closureDepsWriter).
closureCompiler config
closureCompiler: { options: { compilerFile: 'compiler.jar', compilerOpts: { compilation_level: 'ADVANCED_OPTIMIZATIONS' } } }
closureCompiler: { compilerFile: 'compiler.jar' }
compilerFile is required inside options, not at top level. Also compilerOpts is an object, not directly at options level.
closureBuilder config
closureBuilder: { options: { builder: 'closurebuilder.py', root: 'src/', output_mode: 'compiled', compiler: 'compiler.jar' } }
closureBuilder: { builder: 'closurebuilder.py' }
Builder task requires root and compiler option even if not compiling. Output_mode can be 'list', 'script', or 'compiled'.
closureDepsWriter config
closureDepsWriter: { options: { root: 'src/', deps: 'deps.js' } }
closureDepsWriter: { root: 'src/', deps: 'deps.js' }
root and deps should be inside options, not at top level.

Minimal Gruntfile configuring the Closure Compiler task with a jar path, source files, and simple optimizations.

// Install: npm install grunt-closure-tools --save-dev // Gruntfile.js module.exports = function(grunt) { grunt.loadNpmTasks('grunt-closure-tools'); grunt.initConfig({ closureCompiler: { options: { compilerFile: 'node_modules/google-closure-compiler-java/compiler.jar', checkModified: true, compilerOpts: { compilation_level: 'SIMPLE_OPTIMIZATIONS', warning_level: 'verbose' } }, dist: { src: ['src/**/*.js'], dest: 'dist/bundle.min.js' } } }); grunt.registerTask('default', ['closureCompiler']); };
Debug
Known issues
breakingGrunt 0.4.x migration: Task configuration structure changed. Options must be nested under `options` key, not top-level.
fix
Move `compilerFile`, `compilerOpts`, `execOpts` inside `options: {}` block.
affects: >=0.7.0
deprecatedBuilder and DepsWriter depend on Python scripts (closurebuilder.py, depswriter.py) which are deprecated by Google.
fix
Consider migrating to pure Node alternatives like 'google-closure-compiler' for compilation and manual dependency management.
affects: >=1.0.0
gotchacompilerFile must point to an actual closure-compiler.jar. If missing, task fails silently or with Java errors.
fix
Download compiler.jar from https://dl.google.com/closure-compiler/compiler-latest.zip or use npm package 'google-closure-compiler-java' and set path to its jar.
affects: >=0.1.0
gotchaMax buffer exceeded: Node default 200*1024 may be insufficient for large files, causing 'Error: maxBuffer exceeded'.
fix
Set execOpts.maxBuffer in options, e.g., `execOpts: { maxBuffer: 999999 * 1024 }`.
affects: >=0.1.0
gotchaFile paths with glob patterns (e.g., 'src/**/*.js') must be in src array. The grunt file syntax (<config:...>) is NOT supported in src.
fix
Use grunt's usual array of file patterns in src; do not use template syntax like `'<%= pkg.name %>'` in src.
affects: >=0.7.0
Errors
Common errors & fixes
Warning: Task "closureCompiler" not found. Use --force to continue.
The task was not loaded via grunt.loadNpmTasks('grunt-closure-tools').
fix
Add `grunt.loadNpmTasks('grunt-closure-tools');` to your Gruntfile.
Fatal error: java.io.IOException: Cannot run program "/path/to/closure-compiler.jar": error=2, No such file or directory
compilerFile path is incorrect or missing; Java cannot find the jar.
fix
Verify the compilerFile path exists, or use an absolute path. For Windows, ensure forward slashes or escaped backslashes.
Fatal error: maxBuffer exceeded
The output from the compiler command exceeds Node's default buffer size (200KB).
fix
Increase the buffer by setting `execOpts: { maxBuffer: 999999 * 1024 }` in the task options.
Warning: DepsWriter: No files found to process.
The root directory in depsWriter options does not contain any .js files specified by the includes/excludes.
fix
Ensure the `root` path is correct and use the `includes` option (string or array) to specify which files to scan.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
gruntrequiredPeer dependency for Grunt plugin registration (^0.4.0 or ~0.4.1).
Agent activity
4 hits · last 30 days
node
4
Resources
grunt-closure-tools — npm install grunt-closure-tools · libregistry