Skip to content

Instantly share code, notes, and snippets.

@zachwolf
Created February 7, 2016 06:39
Show Gist options
  • Save zachwolf/86ea1cdb143f59fbf5da to your computer and use it in GitHub Desktop.
Save zachwolf/86ea1cdb143f59fbf5da to your computer and use it in GitHub Desktop.
builds less files on request
var Promise = require('bluebird')
, less = Promise.promisifyAll(require('less'))
, path = require('path')
, fs = require('fs')
, through = require('through2')
app.get('/node_modules/bootstrap/less/glyphicons.less', (req, res) => {
res.header("Content-type", "text/css");
fs.createReadStream(path.join(__dirname, './node_modules/bootstrap/less/glyphicons.less'))
.pipe(
through(function (chunk, end, cb) {
this.push(`
//** Load fonts from this directory.
@icon-font-path: "/node_modules/bootstrap/fonts/";
//** File name for all font files.
@icon-font-name: "glyphicons-halflings-regular";
//** Element ID within SVG icon file.
@icon-font-svg-id: "glyphicons_halflingsregular";
${chunk.toString('utf8')}
`)
cb()
})
)
.pipe(
through(function (chunk, enc, cb) {
less.renderAsync(chunk.toString('utf8'))
.then((compiled) => {
this.push(compiled.css)
cb()
})
})
)
.pipe(res)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment