expressjs - not able to load my stylus stylesheet

2019-07-09 10:09发布

In my express app, i am trying to load the style properties from styles module engine. But i couldn't able to load my style at all.

here is my folder structure:

myNodeApp

   -node_modules
   -styles
       -style.css
       -style.styl
   -views
       -index.jade

and here is my app.js code where i call use the stylus.

var http    = require("http"),
    express = require("express"),
    stylus = require("stylus"),
    app = express();

app.set('view engine', 'jade');
app.set('views', './views');

app.use(stylus.middleware({
    debug : true,
    src : __dirname + '/views',
    dest : __dirname + '/styles'
}));

app.use(express.static(__dirname + '/styles'));
app.use(express.static(__dirname + '/css'));

app.get('/', function (req, res, next){
    res.end("<h1>Sample Tittle</h1>");
    next();
});

app.get("/sample", function(req, res) {
    res.render('index');
})

app.listen(1337); 

But nothing is rendered and applied to my jade file at all.

here is my 'index.jade' - file

html
    head
        title welcome to Jade!
        link(rel='stylesheet', href='style.css')
    body
        h1 Test title

what is wrong here, and how to solve it?

1条回答
Viruses.
2楼-- · 2019-07-09 10:44

Shouldn't the stylus middleware get the source from /styles to set the dest to /styles as well ? :

app.use(stylus.middleware({
    debug : true,
    src : __dirname + '/styles',
    dest : __dirname + '/styles'
}));
查看更多
登录 后发表回答