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 serverRouter = require('server-router')
const browserify = require('browserify')
const bankai = require('bankai')
const http = require('http')
const router = createRouter()
http.createServer(function (req, res) {
router(req, res).pipe(res)
}).listen(1337)
function createRouter () {
const router = serverRouter()
const html = bankai.html()
router.on('/', html)
const css = bankai.css({ use: [ 'sheetify-cssnext' ] })
router.on('/bundle.css', css)
const js = bankai.js(browserify, '/src/index.js', { transform: 'babelify' })
router.on('/bundle.js', js)
return router
}
API
bankai.html(opts)
Return an html
stream. Cached by default. Includes livereload if
NODE_ENV=development
. Takes the following options:
- opts.entry:
js
entry point. Defaults to /bundle.js
- opts.css:
css
entry point. Defaults to /bundle.css
bankai.css(opts)
Return a css
stream.
Cached if NODE_ENV=production
. Takes the following options:
- use: array of transforms. Empty by default.
- basedir: project base directory. Defaults to
process.cwd()
bankai.js(browserify, src, opts)
Return a js
stream. Uses watchify
for incremental builds if
NODE_ENV=development
. src
is the bundle entry file. Cached by default.
See Also
License
MIT