Skip to content

Instantly share code, notes, and snippets.

@jessedc
Forked from bentruyman/express-stylus.html
Created April 25, 2011 05:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jessedc/940214 to your computer and use it in GitHub Desktop.
Save jessedc/940214 to your computer and use it in GitHub Desktop.
Using Stylus Middleware with Express
<!doctype html>
<html lang="en">
<head>
<title>My Web Page</title>
<meta charset="utf-8">
<link href="/stylesheets/main.css" rel="stylesheet">
</head>
<body>
</body>
</html>
// The below config assumes all of your stylesheets are being requested from a `/stylesheets/` directory
var express = require('express')
, stylus = require('stylus')
;
var app = express.createServer();
app.configure(function () {
// ... your middleware here
app.use(stylus.middleware({
src: __dirname + '/views' // .styl files are located in `views/stylesheets`
, dest: __dirname + '/public' // .styl resources are compiled `/stylesheets/*.css`
, compile: function(str, path) { // optional, but recommended
return stylus(str)
.set('filename', path)
.set('warn', true)
.set('compress', true);
}
}));
app.use(express.staticProvider(__dirname + '/public'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment