Simple JS closure compiler written in Python that communicates with Google Closure Compiler Service.
Compile a JS file with closure not only reduces the size of the specified files, that is critical in the creation of a modern site, but also ensure
full compatibility with older sites that don't support the new ECMASCRIPT2016, giving you the possibility to use all of its sugar features.
All you need to do is specify a list of the files you want to be compiled
Put the closure_compiler.py
wherever you want and add all the files you want to compile in the .to_closure_compile
file,
one line per file - relative paths are allowed as well.
Example:
index.html
js/
├─closure_compiler.py
├─elements/
├─topbar.js
├─config.js
├─app.js
elements/topbar.js
config.js
app.js
The compiler can be customized to suit your needs.
The configuration is a json dictionary file, it has to be called .closure_compiler_congif.json
.
However, if no config file it's specified, the default values will be used instead
Configuration file structure (below are the default values):
{
"url" : "http://closure-compiler.appspot.com/compile",
"compilation_level" : "WHITESPACE_ONLY",
"output_format" : "text",
"output_info" : "compiled_code",
"output_file" : "app.min.js"
}
- url
- This field shouldn't not be changed, but in case google will change the url, you can specify yours
- compilation_level
- This is the optimization level you want to use. Possible options are WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS and ADVANCED_OPTIONS
- output_format
- This is the format that the server will use to return the file. Possible formats are text, xml and json
- output_info
- This parameter indicates what kind of information the server should return. Possible infos are compiled_code, warnings, errors and statistics
- output_file
- Specify the name of the file you want the compiled_code, or any other information, to be saved
Python 3
Python's package requests, you can install it with pip
using the requirements.txt
file with:
pip install -r requirements.txt