I integrated the stylus
with middleware. but there is no compile
function called at all..
1) How to make compile
method to work
2) How to update 'tcp.css' each time i update 'tcp.styl` file modified
here is my code :
var connect = require('connect'),
serveStatic = require('serve-static'),
stylus = require('stylus');
var app = connect();
app.use(stylus.middleware({
src : __dirname + '/app/css', //inside i have tcp.styl
dest : __dirname + '/app/css', //i require tcp.css
force : true,
compile : function(str, path) {
console.log('compiled'); //not called at all..
return stylus(str, path)
.set('filename', path) //file name i need to update as 'tcp.css'?
.set('warn', true)
.set('compress', true);
}
}));
app.use(serveStatic("app"));
app.listen(5000, function () {console.log("HI", __dirname);}); //works!
file structure:
I looked at your app structure. It doesn't match your configuration. You have your file at
./public/stylus/tcp.styl
but that needs to match yoursrc
stylus configuration option. Set it up with this structure:./public/css/tcp.styl
src: __dirname + '/public'
dest
. It will default to the same assrc
and everything will be simpler./css/tcp.css
./public/css/tcp.css
, to be served by your static middleware after the stylus middleware compiles it.