{"id":25663,"library":"grunt-closure-tools","title":"grunt-closure-tools","description":"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.","status":"maintenance","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/closureplease/grunt-closure-tools","tags":["javascript","gruntplugin","Closure Compiler","minification","Closure Builder","Google Closure Library","Closure tools","Closure DepsWriter","Performance"],"install":[{"cmd":"npm install grunt-closure-tools","lang":"bash","label":"npm"},{"cmd":"yarn add grunt-closure-tools","lang":"bash","label":"yarn"},{"cmd":"pnpm add grunt-closure-tools","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for Grunt plugin registration (^0.4.0 or ~0.4.1).","package":"grunt","optional":false}],"imports":[{"note":"Do not require the module directly; use grunt.loadNpmTasks to register all three multitasks (closureCompiler, closureBuilder, closureDepsWriter).","wrong":"require('grunt-closure-tools');","symbol":"default (task registration)","correct":"grunt.loadNpmTasks('grunt-closure-tools');"},{"note":"compilerFile is required inside options, not at top level. Also compilerOpts is an object, not directly at options level.","wrong":"closureCompiler: { compilerFile: 'compiler.jar' }","symbol":"closureCompiler config","correct":"closureCompiler: { options: { compilerFile: 'compiler.jar', compilerOpts: { compilation_level: 'ADVANCED_OPTIMIZATIONS' } } }"},{"note":"Builder task requires root and compiler option even if not compiling. Output_mode can be 'list', 'script', or 'compiled'.","wrong":"closureBuilder: { builder: 'closurebuilder.py' }","symbol":"closureBuilder config","correct":"closureBuilder: { options: { builder: 'closurebuilder.py', root: 'src/', output_mode: 'compiled', compiler: 'compiler.jar' } }"},{"note":"root and deps should be inside options, not at top level.","wrong":"closureDepsWriter: { root: 'src/', deps: 'deps.js' }","symbol":"closureDepsWriter config","correct":"closureDepsWriter: { options: { root: 'src/', deps: 'deps.js' } }"}],"quickstart":{"code":"// Install: npm install grunt-closure-tools --save-dev\n// Gruntfile.js\nmodule.exports = function(grunt) {\n  grunt.loadNpmTasks('grunt-closure-tools');\n\n  grunt.initConfig({\n    closureCompiler: {\n      options: {\n        compilerFile: 'node_modules/google-closure-compiler-java/compiler.jar',\n        checkModified: true,\n        compilerOpts: {\n          compilation_level: 'SIMPLE_OPTIMIZATIONS',\n          warning_level: 'verbose'\n        }\n      },\n      dist: {\n        src: ['src/**/*.js'],\n        dest: 'dist/bundle.min.js'\n      }\n    }\n  });\n\n  grunt.registerTask('default', ['closureCompiler']);\n};","lang":"javascript","description":"Minimal Gruntfile configuring the Closure Compiler task with a jar path, source files, and simple optimizations."},"warnings":[{"fix":"Move `compilerFile`, `compilerOpts`, `execOpts` inside `options: {}` block.","message":"Grunt 0.4.x migration: Task configuration structure changed. Options must be nested under `options` key, not top-level.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Consider migrating to pure Node alternatives like 'google-closure-compiler' for compilation and manual dependency management.","message":"Builder and DepsWriter depend on Python scripts (closurebuilder.py, depswriter.py) which are deprecated by Google.","severity":"deprecated","affected_versions":">=1.0.0"},{"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.","message":"compilerFile must point to an actual closure-compiler.jar. If missing, task fails silently or with Java errors.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Set execOpts.maxBuffer in options, e.g., `execOpts: { maxBuffer: 999999 * 1024 }`.","message":"Max buffer exceeded: Node default 200*1024 may be insufficient for large files, causing 'Error: maxBuffer exceeded'.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use grunt's usual array of file patterns in src; do not use template syntax like `'<%= pkg.name %>'` in src.","message":"File paths with glob patterns (e.g., 'src/**/*.js') must be in src array. The grunt file syntax (<config:...>) is NOT supported in src.","severity":"gotcha","affected_versions":">=0.7.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Add `grunt.loadNpmTasks('grunt-closure-tools');` to your Gruntfile.","cause":"The task was not loaded via grunt.loadNpmTasks('grunt-closure-tools').","error":"Warning: Task \"closureCompiler\" not found. Use --force to continue."},{"fix":"Verify the compilerFile path exists, or use an absolute path. For Windows, ensure forward slashes or escaped backslashes.","cause":"compilerFile path is incorrect or missing; Java cannot find the jar.","error":"Fatal error: java.io.IOException: Cannot run program \"/path/to/closure-compiler.jar\": error=2, No such file or directory"},{"fix":"Increase the buffer by setting `execOpts: { maxBuffer: 999999 * 1024 }` in the task options.","cause":"The output from the compiler command exceeds Node's default buffer size (200KB).","error":"Fatal error: maxBuffer exceeded"},{"fix":"Ensure the `root` path is correct and use the `includes` option (string or array) to specify which files to scan.","cause":"The root directory in depsWriter options does not contain any .js files specified by the includes/excludes.","error":"Warning: DepsWriter: No files found to process."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}