jb-router-scss

Middleware for jb-router allowing transparent serving of SCSS as CSS

npm install jb-router-scss
8 downloads in the last month

jb-router-scss

jb-router-scss is a plugin for jb-router, easily enabling on-the-fly compilation of SCSS to CSS. In this way, there is no need for a build step before deployment.

Example

First, install with npm:

npm install jb-router
npm install jb-router-scss

and then

var Router = new (require("jb-router"))();
var SCSS = require("jb-router-scss");

Router.Get(/^\/js(\/.+)/, Router.StaticHandler("./static/js"));
Router.Get(/^\/css(\/.+)/, SCSS.CompileSCSS("./static/scss"));

Router.Listen({ "Port": 4000 });

Reference

jb-router-scss exposes one function:

CompileSCSS(LocalPath)
  • LocalPath: a string with the path to the directory, on the server, of the SCSS files to be served by the route.
  • returns a Router::RequestHandler which expects one regular expression group, the file location relative to LocalPath.

Example: see above.

Notes:

  • The request handler expects a request for a file with extension .css. It will then look in LocalPath for the same file but with an extension of .scss. For example, a request for /css/style.css will be answered with the compiled version of ./static/scss/style.scss.

  • The compiled CSS is served with content type text/css.

npm loves you