Created
February 7, 2016 06:39
-
-
Save zachwolf/86ea1cdb143f59fbf5da to your computer and use it in GitHub Desktop.
builds less files on request
This file contains hidden or 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 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