gulp-closure-compiler
raw JSON → 0.4.0 verified Fri May 01 auth: no javascript abandoned
Gulp plugin for Google Closure Compiler that integrates the Closure Compiler Java-based minification and optimization into Gulp build pipelines. Version 0.4.0 (latest) is a stable release with no active development since 2016. It provides SIMPLE and ADVANCED optimization modes, supports custom compiler flags, tiered compilation, and maxBuffer configuration. Unlike alternatives like gulp-google-closure-compiler, this plugin requires a local compiler.jar and does not use the npm-based compiler distribution.
Common errors
error Error: spawn java ENOENT ↓
cause Java is not installed or not in PATH.
fix
Install Java JRE/JDK and ensure 'java' command is available.
error maxBuffer exceeded ↓
cause Closure Compiler output exceeds default buffer size (1000kb).
fix
Pass maxBuffer option: maxBuffer: 2000 for 2MB.
error Cannot find module 'gulp' ↓
cause gulp is not installed as a peer dependency.
fix
Run 'npm install gulp --save-dev'.
Warnings
gotcha compilerPath must point to a local compiler.jar file. The package does not download or bundle the compiler. ↓
fix Download compiler.jar from https://dl.google.com/closure-compiler/compiler-latest.zip and set compilerPath.
gotcha ADVANCED_OPTIMIZATIONS requires proper externs and closure_entry_point, otherwise code may be incorrectly removed. ↓
fix Provide externs for external APIs and set closure_entry_point as the main entry.
deprecated The package is no longer maintained. Consider using gulp-google-closure-compiler or closure-compiler-npm directly. ↓
fix Migrate to gulp-google-closure-compiler or use the official npm closure-compiler package.
gotcha maxBuffer default is 1000kb (in code). If output exceeds this, you get 'maxBuffer exceeded' error. ↓
fix Set maxBuffer option to a higher value in kilobytes.
gotcha Tiered compilation requires JDK 1.7+ and may cause issues on some systems. ↓
fix Ensure JDK is installed and set tieredCompilation: true only if needed.
Install
npm install gulp-closure-compiler yarn add gulp-closure-compiler pnpm add gulp-closure-compiler Imports
- closureCompiler wrong
const { closureCompiler } = require('gulp-closure-compiler')correctimport closureCompiler from 'gulp-closure-compiler' - default (function) wrong
import { closureCompiler } from 'gulp-closure-compiler'correctconst closureCompiler = require('gulp-closure-compiler') - Type (none) wrong
import * as closureCompiler from 'gulp-closure-compiler'correct// No types provided; use @types/gulp-closure-compiler if needed
Quickstart
var gulp = require('gulp');
var closureCompiler = require('gulp-closure-compiler');
gulp.task('default', function() {
return gulp.src('src/*.js')
.pipe(closureCompiler({
compilerPath: 'path/to/compiler.jar',
fileName: 'build.js'
}))
.pipe(gulp.dest('dist'));
});