Bundle up!
Bundle up is a middleware for connect to manage all client-side assets in an organized way.
Fork by @FGRibreau
- Fix
BundleUp(app, asset object | path string, options object);
- Added
.addJsUrl(url [, namespace])
&.addCssUrl(url [, namespace])
- Fix Express 2 & 3
- Bug fix when adding the same file in different bundles
- Added
.addJsObject(object [, namespace])
complete
callback when Bundle up is ready (if in production, when files are minified)
Pound an higher-level asset manager for Node.JS/Express now use this fork of Bundle-up.
Installation
$ npm install bundle-up2
Usage
var BundleUp =assets = ;;// To actually serve the files a static file// server needs to be added after Bundle Upapp
The first parameter to the BundleUp middleware is the app object and the second is the path to the assets file. Through the assets file all client-side assets needs to get added.
// assets.jsmodule {// .addJs(filename [, namespace])assets;assets;assets;assets;// New .addJsUrl(object [, namespace])assets;// addCss(filename [, namespace])assets;assets;// New .addCssUrl(object [, namespace])assets;// New .addJsObject(object [, namespace])assets;// Will create Redsmin.app = {};}
Just point to a file (.js, .css, .coffee or .styl are currently supported) anywhere in your app directory. In your view you can then just render all the css or javascript files by calling renderStyles
and renderJs
like this:
!!!htmlhead!= renderStyles()body!= body!= renderJs()
By default this will render
All assets will be compiled on-the-fly when bundle:false
is set. Therefore the server never
needs to be restarted when editing the different assets.
To render bundles bundle:true
needs to be passed as a parameter to the middleware. This will concatenate all javascript and css files into bundles and render this:
All bundles are min during startup. The filename will change with the content so you should configure your web server with far future expiry headers.
min/
All files that needs to be compiled, copied (if you are bundling up a file that doesn't reside in your public/
directory) or bundled will end up in public/min/
directory. This is to have an organized way to separate whats actually your code and whats min code.
Filtered paths
All files can be added in a directory by using a "filtered path" like this
// assets.jsmodule {assets; //adds all files in /public/js (subdirectories included)assets; //adds all js files in /publicassets; //adds all coffee files in /cs (subdirectories included)});
Namespaces
Sometimes all javascript or css files cannot be bundled into the same bundle. In that case namespaces can be used
// assets.jsmodule {assets;assets;assets;assets;assets;assets;});
!!!htmlhead!= renderStyles()!= renderStyles('ie')body!= body!= renderJs()!= renderJs('en_US')
which will render this with bundle:false
:
and this with bundle:true
:
Donate
License
MIT licensed