Skip to content

Instantly share code, notes, and snippets.

@yoshuawuyts
Created September 21, 2017 18:29
Show Gist options
  • Save yoshuawuyts/962557eea0920d3321dabf56ab467ace to your computer and use it in GitHub Desktop.
Save yoshuawuyts/962557eea0920d3321dabf56ab467ace to your computer and use it in GitHub Desktop.
var bankai = require('./')
var http = require('http')
var path = require('path')
var compiler = bankai(path.join(__dirname, 'example/index.js'), { watch: true })
http.createServer(function (req, res) {
if (req.url === '/index.html' || req.url === '/') {
compiler.documents('index.html', function (err, node) {
if (err) throw err
res.end(node.buffer)
})
} else if (/bundle\.js$/.test(req.url)) {
compiler.scripts('bundle.js', function (err, node) {
if (err) throw err
res.end(node.buffer)
})
} else if (/bundle\.css$/.test(req.url)) {
compiler.style(function (err, node) {
if (err) throw err
res.end(node.buffer)
})
} else {
res.writeHead(404)
res.end()
}
}).listen(8080, function () {
console.log('listening on port 8080')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment