Skip to content

Instantly share code, notes, and snippets.

@sherbondy
Last active January 23, 2017 03:01
Show Gist options
  • Save sherbondy/c589a215c3cdc6e12c9666d0706af581 to your computer and use it in GitHub Desktop.
Save sherbondy/c589a215c3cdc6e12c9666d0706af581 to your computer and use it in GitHub Desktop.
How to try out closure-compiler-js
# I couldn't find any documentation inside the closure-compiler-js repo that explained
# how to actually... use it... from the git source, so here you go:
# I'm on a Mac. You'll need to install maven. It is a dependency
# for build.js to make jscomp.js
brew install maven
git clone git@github.com:google/closure-compiler-js.git
cd closure-compiler-js
# Now you need to pull in the java closure-compiler, which is a submodule:
git submodule update --init
# Apparently the submodule version referenced has a bug though, so we should try pulling the latest compiler:
# https://github.com/google/closure-compiler-js/issues/44
cd closure-compiler
git pull origin master
# Now we need to bootstrap the JavaScript version of the Closure Compiler, referred to as `jscomp.js` in the source:
# (back in the `closure-compiler-js` directory)
cd ..
node build.js
# This will take quite some time. But now we have `jscomp.js`, and we can use `node cmd.js` in the same way that you
# would use `google-closure-compiler-js` as referenced in the documentation, since one is just an alias for the other
# in package.json
node cmd.js --help
# an example, assuming you have some file located at mytest.js
# ./cmd.js --env "CUSTOM" mytest.js
# You can also require `jscomp.js` in a script tag or web worker in the browser and call compile() to use it.
# See `test/simple.js` for an example of the object that compile expects to take as input.
# Sanity check
node test/simple.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment