Code Monkey home page Code Monkey logo

gulp-closure-compiler's Introduction

gulp-closure-compiler

Build Status Dependency Status devDependency Status

Gulp plugin for Google Closure Compiler

Issues with the output or Java should be reported on the Closure Compiler issue tracker.

Install

npm install --save-dev gulp-closure-compiler

Example

Simple optimizations

Simple optimizations for classic minifying.

var gulp = require('gulp');
var closureCompiler = require('gulp-closure-compiler');

gulp.task('default', function() {
  return gulp.src('src/*.js')
    .pipe(closureCompiler({
      compilerPath: 'bower_components/closure-compiler/compiler.jar',
      fileName: 'build.js'
    }))
    .pipe(gulp.dest('dist'));
});

Advanced optimizations

Advanced optimizations is much more aggressive. It's aimed for libraries like Closure Library.

var gulp = require('gulp');
var closureCompiler = require('gulp-closure-compiler');

gulp.task('default', function() {
  return gulp.src('src/*.js')
    .pipe(closureCompiler({
      compilerPath: 'bower_components/closure-compiler/compiler.jar',
      fileName: 'build.js',
      compilerFlags: {
        closure_entry_point: 'app.main',
        compilation_level: 'ADVANCED_OPTIMIZATIONS',
        define: [
          "goog.DEBUG=false"
        ],
        externs: [
          'bower_components/este-library/externs/react.js'
        ],
        extra_annotation_name: 'jsx',
        // Some compiler flags (like --use_types_for_optimization) don't have value. Use null.
        // use_types_for_optimization: null,
        only_closure_dependencies: true,
        output_wrapper: '(function(){%output%})();',
        warning_level: 'VERBOSE'
      }
    }))
    .pipe(gulp.dest('dist'));
});

API

closureCompiler(options)

options

fileName

Type: String
Required

Generated file name.

compilerPath

Type: String
Required

Path to compiler.jar

compilerFlags

Type: Object

Closure compiler flags.

maxBuffer

Type: Number

If the buffer returned by closure compiler is more than 1000kb, you will get an error saying "maxBuffer exceeded". To prevent this, you can set the maxBuffer to the preffered size you want (in kb).

continueWithWarnings

Type: boolean

Ignore the warnings and continue with the compiler. This adds flexiblity to some projects that can't work around certain warnings. Default value is false.

How to download Closure Compiler

Use Bower.

{
  "name": "foo",
  "version": "0.0.0",
  "dependencies": {
    "closure-compiler": "http://dl.google.com/closure-compiler/compiler-latest.zip"
  }
}

Implementation notes

  • Closure compiler supports pipes, but not correctly (issue).
  • You don't need closurebuilder.py script, compiler knows how to resolve dependencies.
  • Java 1.7+ is required.

License

MIT © Daniel Steigerwald

gulp-closure-compiler's People

Contributors

steida avatar hachr avatar monzonj avatar colinrotherham avatar eordano avatar mczolko avatar gobie avatar pvolok avatar stevesloka avatar igorklopov avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.