Skip to content

Simple JS closure compiler that communicates with Google Closure Compiler Service

License

Notifications You must be signed in to change notification settings

andreatulimiero/js_closure_compiler_in_python

Repository files navigation

JS closure compiler in Python

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

Usage

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:

Project's folder structure
index.html
js/
 ├─closure_compiler.py
 ├─elements/
   ├─topbar.js
 ├─config.js
 ├─app.js
.to_closure_compile file structure
elements/topbar.js
config.js 
app.js

Configuration

Configuration file

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"
}

Configuration options

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
Other informations can be found directly in the Google's [site](https://developers.google.com/closure/compiler/docs/gettingstarted_api)

Requirements

Python 3
Python's package requests, you can install it with pip using the requirements.txt file with:

pip install -r requirements.txt

About

Simple JS closure compiler that communicates with Google Closure Compiler Service

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages