Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2015
What would you like to do?
koa middleware to build component.
var fs = require('fs');
var builder = require('component-builder');
var resolver = require('component-resolver');
module.exports = function(options) {
var style, script = builder.scripts.require;
return function* builder(next) {
if (/build\.(js|css)/.test(this.url)) {
var tree = yield resolver(process.cwd(), options);
style = yield buildStyle(tree);
script += yield buildScript(tree);
fs.writeFileSync(, style);
fs.writeFileSync(options.output.script, script);
yield next;
function buildStyle(nodes) {
return new builder.styles(nodes)
.use('styles', builder.plugins.css())
function buildScript(nodes) {
return new builder.scripts(nodes)
.use('scripts', builder.plugins.js())
.use('scripts', builder.plugins.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment