bdlr
v1.4.3
Published
Create and use bundles like you would do in .NET.
Readme
bdlr
Create and use bundles like you would do in .NET.
How to use?
Install
npm install --save bdlrExample
index.js
var bdlr = require('bdlr');
bdlr.createBundle('css', bdlr.STYLE)
.includeBowerComponents()
.includeGlob('src/**/*.css');
bdlr.createBundle('lib', bdlr.SCRIPT)
.includeBowerComponents(true, ['angular-mocks'])
.rebase({'bower_components': 'assets'});
bdlr.createBundle('app', bdlr.SCRIPT)
.includeFile('src/app.js')
.includeGlob('src/**/*.js', ['src/**/*.exclude.js'])
.includeFile('src/main.js');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.get('/', function (_, res) {
res.render('mypage', { bundles: bdlr.bundles });
});
app.use('/bower_components', express.static('bower_components'));mypage.jade
doctype html
html
head
title My Page
| !{bundles.css}
body
block content
| !{bundles.lib}
| !{bundles.app}API
Bdlr
bundles:Object: collection of registred bundlescreateBundle(name:string, type:bdlr.SCRIPT|bdlr.STYLE, renderedUrl:string):Bundle:renderedUrlis what is rendered in productionENV:string: current environnement, default isprocess.env.NODE_ENV. Can be set but onlyprod[uction]change theBundlebehaviors.
Bundle
constructor(type:Bundle.SCRIPT|Bundle.STYLE[, renderedUrl:string])type:number: type of bundle (script or style),typeparam of the constructorurl:string:renderedUrlparam of the constructorfiles:string[]: final list of files in the bundleincludeFile(filePath:string):BundleincludeGlob(glob:string, ignoredGlobs:string[]):BundleincludeBowerComponents([includeDevComponents:boolean, [ignoredPackages:string[]]]):Bundle: add your bower components in the bundle, including the dev components if arguments is truetoString():string: get html tags of the bundle. ifbdlr.ENVis prod,renderedUrlwill be the urlrebase(rebaseConf:object):Bundle: whenbdlr.ENVisdev, allows you to rebase directoriesgetMinifiedContent():string: get the minified content of the bundle
Serve production bundles files with Express
:warning: You should consider a file cache to increase performances.
// ...
var app = express();
var bdlr = require('bdlr');
var includeBowerDevDependencies = true;
bdlr.createBundle('style', bdlr.STYLE, '/style.css')
.includeBowerComponents(includeBowerDevDependencies)
.includeGlob('src/**/*.css');
bdlr.createBundle('lib', bdlr.SCRIPT, '/lib.js')
.includeBowerComponents(includeBowerDevDependencies, ['angular-mocks']);
bdlr.createBundle('app', bdlr.SCRIPT, '/app.js')
.includeFile('src/app.js')
.includeGlob('src/**/*.js', ['src/**/*.exclude.js'])
.includeFile('src/main.js');
bdlr.ENV = 'production';
//...
Object.keys(bdlr.bundles).forEach((bundleName) => {
var bundle = bdlr.bundles[bundleName];
app.get(bundle.url, (req, res) => {
res.set('Content-Type', bundle.type === bdlr.SCRIPT ? 'application/javascript' : 'text/css');
res.send(bundle.getMinifiedContent());
});
});Note
The included files depends on environment of bdlr. You can pass .js, .debug.js or .min.js, the result will be the same :
- in
development: bdlr will search for.debug.jsfiles, if not present, search for.jsand if not present, take.min.js - in
production: bdlr will search for.min.jsfiles, if not present, search for.jsand if not present, take.debug.js
Example
Considering yourFile.debug.js, yourFile.js and yourFile.min.js and a bundle with .includeFile('yourFile.js') or .includeGlob('*.js').
- in
development,yourFile.debug.jswill be taken - in
production,yourFile.min.jswill be taken
Dev note
To run the tests, simply install mocha globally and run:
mocha