node.jsstylusnode.js-connect

stylus - middleware not compiling the `styl` file


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: file structure image


Solution

  • 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 your src stylus configuration option. Set it up with this structure: