expressjs - not able to load my stylus stylesheet to jade html page

你离开我真会死。 提交于 2020-01-05 03:05:25

问题


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:


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'
}));


来源:https://stackoverflow.com/questions/20635078/expressjs-not-able-to-load-my-stylus-stylesheet-to-jade-html-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!