The general idea behind plovr is that all of the configuration for your Closure build should be stored in a single file of JSON. (Ultimately, config files will be able to inherit from other config files, but that feature does not exist today.) The following is an example of a minimal (but functional) plovr config file:
// File: config.js
{
"id": "sample",
"paths": ".",
"inputs": "main.js"
}
An example of a more complex config file (that leverages the modules feature of the Compiler) can be seen in the plovr repository. A config file declares which files should be compiled, where its dependencies can be found, and which compilation options should be used. (Many of these settings have appropriate default values and need not be specified.)When plovr is started in server mode, it takes the path to one or more config files as input:
java -jar plovr.jar serve config.jsOnce the plovr web server is started, it should not need to be restarted unless one of the config files is edited. (Some settings can be changed via query parameters, avoiding the need to restart plovr.) The primary way to access the output of plovr is by making a GET request. By default, plovr runs on port 9810, so loading the following URL in a browser will return the compiled code for the configuration with the specified id:
http://localhost:9810/compile?id=sampleThis means that when developing your web application, you will need a
<script>
tag whose src
attribute refers to the plovr URL that is shown above. This means that you will need to add logic to your web server to load JavaScript from plovr in development mode, but to load JavaScript from wherever your other static content is hosted in production mode. Hopefully your build system already has conditional logic for development and production modes that you can leverage in integrating plovr to your development process.Once plovr is up and running, it will discover new JavaScript and Soy files that are added under directories specified by paths
in the config file. For this reason, it is often easiest to declare a single file for inputs
, such as main.js
, and add or remove goog.require()
and goog.provide()
statements as appropriate to transitively include the desired libraries. This avoids the need to restart plovr and makes the insertion point for your application unambiguous.
java -jar plovr.jar build config.js > sample-compiled.jsIt is up to you to upload
sample-compiled.js
to your static content server and to make sure that in production, the src
attribute of your <script>
tag points to sample-compiled.js
.(It is quite possible that future work for plovr will include better integration with popular web frameworks, such as Django, that will facilitate this process.)
The primary options of interest are likely the compilation mode and the warning level. The names of these properties in the plovr config are mode
and level
, respectively. The possible string values for mode
are:
RAW
Loads each input via its own <script>
tag: does NOT run the Compiler, so no checks are performed.WHITESPACE
Loads all of the JavaScript code concatenated together with all whitespace and comments removed.SIMPLE
Loads the JavaScript as compiled with SIMPLE_OPTIMIZATIONS
enabled.ADVANCED
Loads the JavaScript as compiled with ADVANCED_OPTIMIZATIONS
enabled.level
are QUIET
, DEFAULT
, and VERBOSE
, which correspond exactly to the warning levels supported by the Closure Compiler. Therefore, to change config.js
to use the most aggressive compilation settings, set mode
and level
as follows:
{ "id": "sample", "paths": ".", "inputs": "main.js", "mode": "ADVANCED", "level": "VERBOSE" }It is also possible to set the level for various types of Compiler checks with the
checks
property. Many of these checks are explained on the Closure Compiler wiki, though the DIAGNOSTIC_GROUP_NAMES
variable in DiagnosticGroups.java is the real source of truth:
{
"id": "sample",
"paths": ".",
"inputs": "main.js",
"mode": "ADVANCED",
"level": "VERBOSE",
"checks": {
// acceptable values are "ERROR", "WARNING", and "OFF"
"deprecated": "ERROR",
"checkTypes": "ERROR",
"nonStandardJsDocs": "WARNING"
}
}
(Strictly speaking, JSON does not support comments in either the //
or /* */
form, but such comments are allowed in plovr config files.)Remember, the names and values of the config file have not been finalized, so it may be necessary to monitor the plovr source code as new versions are released.
One important thing to note when using modules is that you will probably have to add code like the following to configure the goog.module.ModuleManager
:
var moduleManager = goog.module.ModuleManager.getInstance(); moduleLoader.setDebugMode(true); moduleManager.setAllModuleInfo(goog.global['PLOVR_MODULE_INFO']); moduleManager.setModuleUris(goog.global['PLOVR_MODULE_URIS']);When plovr generates the JavaScript for the modules, it includes some module data in global variables that are used for initialization, as shown above.
/compile
URL introduced in the first section, there are other URLs that plovr serves to provide additional information. Some of these are listed on the plovr wiki page on Google Code, though the best way to get the complete list is by exploring the plovr source code. There is also more information on these features of plovr in Appendix C of Closure: The Definitive Guide.