You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Closure Compiler’s 2018-05-06JAR-file is included with the gem.
Installation
sudo gem install closure-compiler
Usage
The Closure::Compiler has a compile method, which can be passed a string or an open IO object, and returns the compiled JavaScript. The result is returned as a string, or, if a block is passed, yields as an IO object for streaming writes.
The Closure::Compiler also has compile_file and compile_files methods, which can be passed a file path or an array of file paths respectively. The files are concatenated and compiled and, like the compile method, the result is returned as a string or, if block is passed, yields an IO object.
The default values of all the compiler flags are identical to the command-line version. The default compilation_level is “SIMPLE_OPTIMIZATIONS”.
A Closure::Error exception will be raised, explaining the JavaScript syntax error, if compilation fails for any reason.
YUI Compressor Compatibility
Effort has been made to make the “closure-compiler” gem a drop-in alternative to the “ruby-yui-compressor”. To that end, Closure::Compiler#compile has been aliased as compress, and can take the same string or IO argument that a YUI::JavaScriptCompressor#compress can. In addition, the Closure::Compiler initializer can take java and jar_file options, overriding the location of the Java command and the Closure Compiler JAR file, respectively.