mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-06-13 05:55:26 +00:00
update
This commit is contained in:
40
node_modules/bs-recipes/recipes/middleware.css.injection/app.js
generated
vendored
Normal file
40
node_modules/bs-recipes/recipes/middleware.css.injection/app.js
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Require Browsersync
|
||||
*/
|
||||
var browserSync = require("browser-sync");
|
||||
|
||||
/**
|
||||
* Run the middleware on files that contain .less
|
||||
*/
|
||||
function lessMiddleware (req, res, next) {
|
||||
var parsed = require("url").parse(req.url);
|
||||
if (parsed.pathname.match(/\.less$/)) {
|
||||
return less(parsed.pathname).then(function (o) {
|
||||
res.setHeader('Content-Type', 'text/css');
|
||||
res.end(o.css);
|
||||
});
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile less
|
||||
*/
|
||||
function less(src) {
|
||||
var f = require('fs').readFileSync('app' + src).toString();
|
||||
return require('less').render(f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run Browsersync with less middleware
|
||||
*/
|
||||
browserSync({
|
||||
files: "app/css/*.less",
|
||||
server: "app",
|
||||
injectFileTypes: ["less"],
|
||||
/**
|
||||
* Catch all requests, if any are for .less files, recompile on the fly and
|
||||
* send back a CSS response
|
||||
*/
|
||||
middleware: lessMiddleware
|
||||
});
|
Reference in New Issue
Block a user