-
Notifications
You must be signed in to change notification settings - Fork 1
Configuration
##web.xml
The ResourceServlet configuration is used to point out the bundle configuration files.
<servlet>
<servlet-name>fnug</servlet-name>
<servlet-class>fnug.ResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>config</param-name>
<param-value>/bundles.js</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>fnug</servlet-name>
<url-pattern>/rs/*</url-pattern>
</servlet-mapping>
config servlet init parameter is used to point out the bundle configuration file(s). Several files can be used delimiting with comma (,). I.e. /config1.js, /config2.js, /config3.js. Configs are read using Class.getResource() so are relative to the classpath. This means configurations can either be placed in the WEB-INF/classes/ directory in your webapp, or inside a .jar-file in WEB-INF/lib/.
##Bundle Config
The bundle config file, pointed out by the servlet init parameter, configures on or several bundles. The file format is a relaxed JSON to not require object keys to be string literals as in "basePath": "/foo". The bundle config file shall be encoded using UTF-8 charset encoding.
{
mybundle1: {
basePath: '/stuffhere/,
checkModified: 3000,
files: [
'mypackage/sourcefile.js' <-- array of "entry" files for dependency resolution.
],
jsCompilerArgs: '--compilation_level ADVANCED_OPTIMIZATIONS',
jsLint: '/*jslint white: true, browser: true, onevar: false, undef: true, nomen: true, eqeqeq: true, plusplus: false, bitwise: true, regexp: true, newcap: true, immed: true, maxerr: 100, maxlen: 100 */'
},
mybundle2: {
...
}
}
bundle name - The enclosing object for each section is keyed wth the name for that bundle. In the above example we have two bundles mybundle1 and mybundle2.
basePath (optional) - Class path relative base path for resources served from this bundle. The default value is the same directory the bundle config file is in. Example, if the resource servlet is mounted under /rs/*, the basePath is set to /stuffhere/ and we get an http request such as /rs/mybundle1/myresource.js, the resulting path being resolved from the classpath would be /stuffhere/mybundle1/myresource.js. Resources are always resolved using Class.getResource(), there's no way to load resources from an arbitrary place in the file system - they must be on the classpath.
checkModified (optional) - Interval in milliseconds between last modified checks in the bundle. The default value is 3000. Set this to 0 to turn off modified checks (for static bundles such as non-changing 3rd party libraries). For turning off modified checks in deployment, consider using FNUG_OPTS environment variable. The minimum value is 1000 since some file system's minimum time resolution is 1 second.
files (optional) - Files used as entry point when constructing a compressed version of the bundle. This is typically a small set of "entry point" files that use @requires dependency resolution to drag in the rest of the application. The order of the files is respected as long as no dependency requires the order to be changed. As such, the list can be used to declare a set of files to load without using dependency resolution. The format for each entry has to be [bundle]/[path-to-resource]. Files can either be from the local bundle, i.e. mybundle1/some/file.js or other bundles mybundle2/another.js, note that also files from the local bundle has to have the local bundle name. The type of files that are meaningful to be declared are javascript (.js) and stylesheets (.css) - you can mix both.
jsCompilerArgs (optional) - These are compilation options passed directly to the Google Closure Compiler. Default is --warning_level QUIET. Two arguments are, if specified, ignored --js_output_file and --js since these control the input/output of the compiler. For more information look at the closure compiler documentation.
jsLint (optional) - A string of jslint options exactly as output by the http://www.jslint.com page. If not provided, jslint is turned off. Notice that jslint results are only available when loading resources through the bootstrap with ?debug=1 or other debug flags.
###Bundle config in JavaScript aware IDE's Since some IDE's such as Eclipse (with JavaScript facet) might be a bit picky about having only valid JavaScript as the content of a .js file the parser only reads from the first { up until the last } of the file. This makes it possible to do the following constructs:
var bundles = {
myBundle: ...
}
or
(function() ( {
mybundle: ...
}
));
##Environment variables
Some options are available aimed at deployment. The options are either set with environment variable FNUG_OPTS or passed as a java property with -Dfnug.opts=.
export FNUG_OPTS=nomodify,precompile,nojslint
nomodify - Turns off all file last modified checks, regardless of the setting in the bundle config.
precompile - Compiles all bundle file lists on startup, not on first request.
nojslint - Completely disables jslinting.