npm install compact
var compact =;
destPathis the path that compact should use to store the compacted assets. If this directory does not exist, it will be created.
webPathis the public public facing route to your
destPath(This will preceed the filename of the output
webPath: '/js/compact/' -> <script src="/js/compact/myscript.js">).
debugis optional. If set to true, the scripts will not be concatenated or minified.
Namespaces are used to create different compilations of scripts. Usually, you will want to create a
global namespace that is used everywhere:
If you have some collection of scripts that will only be used on certain pages, it is a good idea to create a namespace for it. For example, if you have a banner and some ads that only appear on the homepage, and some UI that appears only on the profile page/section:
When creating a namespace, you can also pass in an extra
srcPath. Calls to
addJs() will look for the file in the given
srcPath, and if not found it then tries the
srcPath passed to
If you have created a
global namespace, apply it to all routes like so:
This will expose the view helper
compactJsHtml() in your templates, so you can output the necessary
Selectively apply namespaces to routes:
Note: compact must be applied to your route before the route logic. This is so that the view helper is available when you try to render your layout.
You can defined all the namespaces and js files in a JSON schema using the configure function.
var compact = ;compact;
Any route that has
compact.js() applied will have the helper function
compactJsHtml() available. This will render the relevant script tags. In Jade, Use like so:
From the examples above, on
/ you'd get the following
/blog you'd get this
You also have access to the
compactJs() helper which will return an array
of files instead of the rendered html.
Licenced under the New BSD License