Stylus and Express - stylesheets are not re-compiled when modified

后端 未结 3 1250
误落风尘
误落风尘 2020-12-28 15:20

I am running latest version of Node on Mac OS X. I\'ve installed Express together with Stylus. Also the latest versions.

Stylus is not re-compiling my .styl

相关标签:
3条回答
  • 2020-12-28 15:23

    Default settings Express.js

    app.use(require('stylus').middleware(path.join(__dirname, 'public')));
    

    Stylus compress setting Express.js you must add the style sheet in the document, page loading is compiled and compresses the css

    app.use(require('stylus').middleware({src: path.join(__dirname, 'public'), compress: true}));
    
    0 讨论(0)
  • 2020-12-28 15:28

    It can be too late now, but I've just passed some hours ( T__T ) on this, and I think it's a bug of jade or something like that. I'll explain myself: With this code in server.js:

    app.set('views', __dirname + '/views');
    app.set('view engine', 'jade');
    app.use(
      stylus.middleware({
        src:  __dirname + "/assets/stylus", 
        dest: __dirname + "/assets/css",
        debug: true,
        compile : function(str, path) {
          console.log('compiling');
          return stylus(str)
            .set('filename', path)
            .set('warn', true)
            .set('compress', true);
        }
      })
     );
    app.use(express.static(__dirname + '/assets'));
    

    and in the index.jade:

    link(rel="stylesheet", href="css/style.css")
    

    it works perfectly. The problem was when in the link tag there was:

    link(rel="stylesheet", href="stylesheets/style.css")
    

    and then it was not recompiling at all.

    I hope this will help

    0 讨论(0)
  • 2020-12-28 15:33

    Put static() below the stylus middleware.

    0 讨论(0)
提交回复
热议问题