Code Monkey home page Code Monkey logo

closurecompiler.js's Introduction

ClosureCompiler.js - Closure Compiler for node.js

The all-round carefree package. Automatically downloads and sets up Closure Compiler and a JRE built from OpenJDK if required. No environment variables to set, works out of the box.

Installation

Install: npm -g install closurecompiler

Installing globally is recommended if no global JRE is available and the bundled JRE needs to be downloaded, which is about 45mb large.

ClosureCompiler API

The API is quite simple and fully explained in a few lines of code:

var ClosureCompiler = require("closurecompiler");

ClosureCompiler.compile(
    ['file1.js', 'file2.js'],
    {
        // Options in the API exclude the "--" prefix
        compilation_level: "ADVANCED_OPTIMIZATIONS",
        
        // Capitalization does not matter 
        Formatting: "PRETTY_PRINT",
        
        // If you specify a directory here, all files inside are used
        externs: ["externs/file3.js", "externs/contrib/"],
        
        // ^ As you've seen, multiple options with the same name are
        //   specified using an array.
        ...
    },
    function(error, result) {
        if (result) {
            // Write result to file
            // Display error (warnings from stderr)
        } else {
            // Display error...
         }
    }
);

Command line utility

Usage:   ccjs sourceFiles...|- [--option=value --flagOption ...] [> outFile]

Available options

The API and ccjs support all the command line options of Closure Compiler except --js and --js_output_file.

Additionally, the JVM parameters -Xms and -Xmx are supported just in case that you run out of heap space compiling a rather large code base. When omitted, -Xmx defaults to 1024m.

Usage with Grunt and Gulp

Externs for ADVANCED_OPTIMIZATIONS

Externs for node.js

ClosureCompiler.js depends on the closurecompiler-externs package, an npm distribution of node.js Closure Compiler Externs, which includes externs for all of node's core modules. As a result, specifiying --externs=node automatically includes all node.js specific externs in your compile step. If you are using non-core modules, you may still need additional externs for these.

Updating

To update ClosureCompiler.js and/or the underlying Closure Compiler package, just run npm update. This will automatically download and set up the latest version of Closure Compiler to be used by ClosureCompiler.js.

Using custom Closure Compiler builds

If you want to use a custom Closure Compiler build for whatever reason, just replace the files in the compiler/ directory.

Documentation

Tests Build Status

Contributors

Feross Aboukhadijeh

License

ClosureCompiler.js and Closure Compiler itself

Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html

Rhino

MPL 2.0 License - https://developer.mozilla.org/en-US/docs/Rhino/License

Bundled JRE

Binary License for OpenJDK - http://openjdk.java.net/legal/binary-license-2007-05-08.html

This package is not officially supported by Google, Mozilla or Oracle. All rights belong to their respective owners.

closurecompiler.js's People

Contributors

dcodeio avatar chadkillingsworth avatar feross avatar steida avatar davidaurelio avatar edwarddavidbaker avatar kethinov avatar sindresorhus avatar drjokepu avatar terinjokes avatar

Watchers

James Cloos avatar dj@!LhaNy - Putr@ Atjeh 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.