Created
February 13, 2011 19:27
-
-
Save bentruyman/824982 to your computer and use it in GitHub Desktop.
Using Stylus Middleware with Express
This file contains 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
<!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> |
This file contains 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
// 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, fn) { // optional, but recommended | |
stylus(str) | |
.set('filename', path) | |
.set('compress', true) | |
.render(fn); | |
} | |
})); | |
app.use(express.static(__dirname + '/public')); | |
}); |
For anyone having problems, it's important to call app.use(require('stylus').middleware('/path'))
BEFORE calling app.use(express.static('..'))
@floriansegginger thanks! Awesome tip!
@floriansegginger thanks, finally got this working :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At least in Stylus 0.51.x the
compile
option should be like this:Note that no
render
is invoked, nocb
argument present incompile
and the function must return stylus renderer.