Last active
August 29, 2015 14:00
-
-
Save bodokaiser/36cdab1a3d731dca57e8 to your computer and use it in GitHub Desktop.
koa middleware to build component.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(options.output.style, style); | |
fs.writeFileSync(options.output.script, script); | |
} | |
yield next; | |
}; | |
}; | |
function buildStyle(nodes) { | |
return new builder.styles(nodes) | |
.use('styles', builder.plugins.css()) | |
.end(); | |
} | |
function buildScript(nodes) { | |
return new builder.scripts(nodes) | |
.use('scripts', builder.plugins.js()) | |
.use('scripts', builder.plugins.json()) | |
.end(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment