20200517.0.0 • Published 8 days ago

google-closure-compiler v20200517.0.0

Weekly downloads
92,682
License
Apache-2.0
Repository
github
Last release
8 days ago

google-closure-compiler

Build Status npm version

Check, compile, optimize and compress Javascript with Closure-Compiler

This repository tracks issues related to the publication to npmjs.org and associated plugins. Any bugs not related to the plugins themselves should be reported to the main repository.

Getting Started

If you are new to Closure-Compiler, make sure to read and understand the compilation levels as the compiler works very differently depending on the compilation level selected.

For help or questions with the compiler, the best resource is Stack Overflow. Posts there are monitored by multiple Closure Compiler team members.

You may also post in the Closure Compiler Discuss Google Group.

Please don't cross post to both Stackoverflow and Closure Compiler Discuss.

The compiler is distributed as a Java jar or as a JavaScript library.

Java Version

Requires java to be installed and in the path. Using the java version typically results in faster compilation times.

JavaScript Version

This is a transpiled version of the Java source to native JavaScript. It can be used in environments without java installed and even in a browser.

Note: not all flags are available for the JavaScript version.

Usage

The simplest way to invoke the compiler (e.g. if you're just trying it out) is with npx:

npx google-closure-compiler --js=my_program.js --js_output_file=out.js

Installation

npm install --save google-closure-compiler

Configuration

See the full list of compiler flags.

The build tool plugins take options objects. The option parameters map directly to the compiler flags without the leading '--' characters. You may also use camelCase option names.

Values are either strings or booleans. Options which have multiple values can be arrays.

  {
    js: ['/file-one.js', '/file-two.js'],
    compilation_level: 'ADVANCED',
    js_output_file: 'out.js',
    debug: true
  }

For the java version, some shells (particularly windows) try to do expansion on globs rather than passing the string on to the compiler. To prevent this it is necessary to quote certain arguments:

  {
    js: '"my/quoted/glob/**.js"',
    compilation_level: 'ADVANCED',
    js_output_file: 'out.js',
    debug: true
  }

Build Tool Plugins

The compiler package also includes build tool plugins for Grunt and Gulp. There is also an official webpack plugin.

Advanced Java Version Usage

Changing the Path to the Java SDK

Override the path before first use.

const Compiler = require('google-closure-compiler');

Compiler.prototype.javaPath = '/node_modules/MODULE_NAME/jre/jre1.8.0_131.jre/Contents/Home/bin/java';

const compiler = new Compiler({args});

Running the compiler using nailgun

This gets around the long startup time of Google Closure Compiler using Nailgun, which runs a single java process in the background and keeps all of the classes loaded.

First you need to install closure-gun by running the following command.

npm install closure-gun

Then point the package to use closure-gun rather than the JDK.

const compilerPackage = require('google-closure-compiler');

compilerPackage.compiler.JAR_PATH = undefined;
compilerPackage.compiler.prototype.javaPath = './node_modules/.bin/closure-gun'

Note that when using gulp, Only invocations without gulp.src work with nailgun.

Native Node Usage (for Plugin Authors)

A low-level node class is included to facilitate spawning the compiler jar as a process from Node. In addition, it exposes a static property with the path to the compiler jar file.

Java Version

const ClosureCompiler = require('google-closure-compiler').compiler;

console.log(ClosureCompiler.COMPILER_PATH); // absolute path the compiler jar
console.log(ClosureCompiler.CONTRIB_PATH); // absolute path the contrib folder which contains

const closureCompiler = new ClosureCompiler({
  js: 'file-one.js',
  compilation_level: 'ADVANCED'
});

const compilerProcess = closureCompiler.run(function(exitCode, stdOut, stdErr) {
  //compilation complete
});

JavaScript Version

const ClosureCompiler = require('google-closure-compiler').jsCompiler;

console.log(ClosureCompiler.CONTRIB_PATH); // absolute path the contrib folder which contains

const closureCompiler = new ClosureCompiler({
  compilation_level: 'ADVANCED'
});

const compilerProcess = closureCompiler.run(function(exitCode, stdOut, stdErr) {
  //compilation complete
}, [{
 path: 'file-one.js',
 src: 'alert("hello world")',
 sourceMap: null // optional input source map
}]);

License

Copyright 2015 The Closure Compiler Authors

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Version History

Closure Compiler release notes can be found on the main repository wiki.

20200517.0.0

17 days ago

20200504.0.0

29 days ago

20200426.0.0

1 month ago

20200406.0.0

2 months ago

20200315.0.0

3 months ago

20200224.0.0

3 months ago

20200204.0.0

4 months ago

20200112.0.0

5 months ago

20200101.0.0

5 months ago

20191111.0.0

7 months ago

20191027.0.0

7 months ago

20190929.0.0

8 months ago

20190909.0.0

9 months ago

20190819.0.0

10 months ago

20190729.0.0

10 months ago

20190709.0.0

11 months ago

20190618.0.0

12 months ago

20190528.1.0

12 months ago

20190528.0.0

1 year ago

20190513.0.0

1 year ago

20190415.0.0

1 year ago

20190325.0.0

1 year ago

20190301.0.0

1 year ago

20190215.0.2

1 year ago

20190215.0.1

1 year ago

20190121.0.0

1 year ago

20190106.0.0

1 year ago

20181210.0.0

1 year ago

20181125.1.0

1 year ago

20181205.0.0

1 year ago

20181125.0.1

2 years ago

20181028.0.1

2 years ago

20181028.0.0

2 years ago

20181008.0.0

2 years ago

20180910.1.0

2 years ago

20180910.0.0

2 years ago

20180805.0.0

2 years ago

20180716.0.1

2 years ago

20180716.0.0

2 years ago

20180610.0.2

2 years ago

20180610.0.1

2 years ago

20180610.0.0

2 years ago

20180506.0.0

2 years ago

20180402.0.0

2 years ago

20180319.0.0

2 years ago

20180204.0.0

2 years ago

20180101.0.0

2 years ago

20171203.0.0

2 years ago

20171112.0.0

3 years ago

20171023.0.1

3 years ago

20171023.0.0

3 years ago

20170910.0.0

3 years ago

20170806.0.0

3 years ago

20170626.0.0

3 years ago

20170521.0.0

3 years ago

20170423.0.0

3 years ago

20170409.0.0

3 years ago

20170218.0.0

3 years ago

20170124.0.0

3 years ago

20161201.0.0

3 years ago

20161024.3.0

4 years ago

20161024.2.0

4 years ago

20161024.1.0

4 years ago

20161024.0.0

4 years ago

20160911.0.0

4 years ago

20160822.2.0

4 years ago

20160822.1.0

4 years ago

20160822.0.0

4 years ago

20160713.3.0

4 years ago

20160713.2.0

4 years ago

20160713.1.0

4 years ago

20160713.0.0

4 years ago

20160619.0.0

4 years ago

20160517.1.0

4 years ago

20160517.0.0

4 years ago

20160315.2.0

4 years ago

20160315.1.0

4 years ago

20160315.0.0

4 years ago

20160208.7.0

4 years ago

20160208.6.0

4 years ago

20160208.5.0

4 years ago

20160208.4.0

4 years ago

20160208.3.0

4 years ago

20160208.2.0

4 years ago

20160208.1.0

4 years ago

20160208.0.0

4 years ago

20160125.0.0

4 years ago

20151216.2.0

4 years ago

20151216.1.0

4 years ago

20151216.0.0

4 years ago

20151130.6.0

4 years ago

20151130.5.0

5 years ago

20151130.4.0

5 years ago

20151130.3.0

5 years ago

20151130.2.0

5 years ago

20151130.1.0

5 years ago

20151130.0.0

5 years ago

20151128.4.0

5 years ago

20151128.3.0

5 years ago

20151128.2.0

5 years ago

20151128.1.0

5 years ago

20151128.0.0

5 years ago

20151125.1.0

5 years ago

20151125.0.0

5 years ago

20151123.1.0

5 years ago

20151123.0.0

5 years ago

20151122.6.0

5 years ago

20151122.5.0

5 years ago

20151122.4.0

5 years ago

20151122.3.0

5 years ago

20151122.2.0

5 years ago

20151122.1.0

5 years ago

20151122.0.0

5 years ago

20151015.7.0

5 years ago

20151015.6.0

5 years ago

20151015.5.0

5 years ago

20151015.4.0

5 years ago

20151015.3.0

5 years ago

20151015.2.0

5 years ago

20151015.1.0

5 years ago

20151015.0.0

5 years ago

20150920.0.0

5 years ago

20150901.0.0

5 years ago

20150729.0.0

5 years ago

20150609.0.0

5 years ago

20150505.0.0

5 years ago

20150315.0.2

5 years ago

20150315.0.1

5 years ago

20150315.0.0

5 years ago