rekow / closure-compiler-stream

Simple stream interface for closure compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#closure-compiler-stream Streaming interface for closure compiler.

##Installation Add to your devDependencies:

  "dependencies": {...},
  "devDependencies": {
    "closure-compiler-stream": "~0.1.15"
  },
  ...

or install directly:

npm install --save-dev closure-compiler-stream

then import in your build script:

var closure = require('closure-compiler-stream');

##Usage As a simple streaming compiler:

var closure = require('closure-compiler-stream'),
  fs = require('fs');

// As an intermediary step in a flow
fs.createReadStream('path/to/js/src')
  .pipe(closure())
  .pipe(fs.createWriteStream('path/to/minified.js'));

// As the terminus in a flow
fs.createReadStream('path/to/js/src')
  .pipe(closure({
    js_output_file: 'path/to/minified.js'
  }));

With streaming build tools like gulp:

var gulp = require('gulp'),
  closure = require('closure-compiler-stream'),
  sourcemaps = require('gulp-sourcemaps');

// Basic compile
gulp.task('closure', function () {
  return gulp.src('path/to/js/*.js')
    .pipe(closure())
    .pipe(gulp.dest('path/to/minified/js/'));
});

// With sourcemaps
gulp.task('closure:sourcemap', function () {
  return gulp.src('path/to/js/*.js')
    .pipe(sourcemaps.init())
    .pipe(closure())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('path/to/minified/js/'));
});

##API

var writableStream = closure(options);

options is a map of flags to invoke the compiler with. Options accepts one additional key jar, which can be a string path to a Closure Compiler jar file - use this to override the version of Closure Compiler to use.

To specify modules use the following schema:

module: [
  ['module_name:#files:deps:', 'sourceFile1.js', 'sourceFile2.js']
];

which would be outputted as the flags:

--module module_name:#files:deps: --js sourceFile1.js --js sourceFile2.js

Returns a Writable stream.

About

Simple stream interface for closure compiler

License:MIT License


Languages

Language:JavaScript 100.0%