bankai
DIY asset server. Serves HTML, CSS and JS as streams. Sets proper
Content-Type
encodings and buffers where possible for sub-milisecond response
times in production and development.
Installation
$ npm install bankai
Usage
const browserify = require('browserify')
const bankai = require('bankai')
const http = require('http')
const path = require('path')
const client = path.join(__dirname, 'client.js')
const assets = bankai()
const js = assets.js(browserify, client)
const html = assets.html()
const css = assets.css()
http.createServer((req, res) => {
switch req.url {
case '/': return html(req, res).pipe(res)
case '/bundle.js': return js(req, res).pipe(res)
case '/bundle.css': return css(req, res).pipe(res)
default: return res.statusCode = 404 && res.end('404 not found')
}
}).listen(8080)
API
assets = bankai(opts?)
- optimize: default
false
. Disable livereload scripts, cache output and
optimize all bundles.
assets.html(opts?)
Return an html
stream. Takes the following options:
- opts.entry:
js
entry point. Defaults to /bundle.js
- opts.css:
css
entry point. Defaults to /bundle.css
assets.css(opts?)
Return a css
stream using sheetify.
. Takes the following options:
- use: array of transforms. Empty by default.
- basedir: project base directory. Defaults to
process.cwd()
assets.js(browserify, src, opts?)
Return a js
stream. src
is the bundle entry file. opts
are passed
directly to browserify
CLI
$ node ./bin/ --help
DIY asset server
Usage
$ bankai <command> [options]
Commands
start Start a bankai server
Options
-e, --entry=<id> Resolve <id> from cwd and use as entry module [default: .]
Entry module is expected to export `() -> app`
-p, --port=<n> Bind bankai to <n> [default: 1337]
-o, --optimize Optimize the page and all assets served by bankai [default: false]
-b, --browse=<app> Browse the page served by bankai with <app> [default: false]
--html.entry=<uri> Serve client js at <uri> [default: bundle.js]
--html.css=<uri> Serve client css at <uri> [default: bundle.css]
--html.favicon Disable favicon [default: true]
--html.title Title to use for page
--html.lang Lang attribute to use [default: en]
--css.use sheetify plugins to use
--js.<opt>=<value> Pass key <opt> with <value> to browserify
Examples
$ bankai start
Started bankai for index.js on http://localhost:1337
$ bankai start --entry=basic
Started bankai fro basic/index.js on http://localhost:1337
$ bankai start --port=3000
Started bankai for index.js on http://localhost:3000
$ bankai start --open
Started bankai for index.js on http://localhost:1337
Opening http://localhost:1337 with default browser
$ bankai start --open Safari
Started bankai for index.js on http://localhost:1337
Opening http://localhost:1337 with system browser
$ bankai start --html.title bankai
Started bankai for index.js on http://localhost:1337
$ bankai start --css.use sheetify-cssnext
Started bankai for index.js on http://localhost:1337
$ bankai start --js.fullPaths=false
Examples
Projects showing exemplary usage are provided. Install root project dependencies,
example project dependencies and execute npm start
to start an example.
- Basic - Showing default settings, Hot Module Replacement
See Also
License
MIT