express.js,手写笔没有编译css

时间:2016-08-01 15:47:47

标签: express stylus

我已经掌握了Node.JS / Express.JS和Stylus,但我遇到了问题。我尝试了很多东西,但是手写笔不会编译我的CSS。我用谷歌搜索它,堆栈溢出它,没有一个解决方案有效。我想我错过了一些微不足道的东西或者看错了角度。你可以帮我解决手写笔在PUG模板渲染时自动编译我的css吗?

这是服务器.js:

    (function initialize(){
        //TODO: set dependencies
        var express = require('express');
        var http = require('http');
        var util = require('util');
        var stylus = require('stylus');
        var image = require('./routes/image');

        //TODO: set variables and constants
        var port = 8080;
        var hostname = 'localhost';

        //TODO: create express
        var app = express();

        //TODO: setup the template engine
        app.set('views', './views');
        app.set('view engine', 'pug');
        app.use(express.static(__dirname + '/public'));
        app.use(stylus.middleware({
            src: __dirname + '/resources',
            dest: __dirname + '/public',
            debug: true,
            force: true
        }));

        //TODO: set the default GET route
        app.get('/', image.snatch);

        //TODO: create the server
        var server = http.createServer(app);

        //TODO: start the server
        server.listen(port, hostname, function start(){
            console.log(util.format('Server is running at http://%s:%s/', hostname, port));
        });
    }());

这是image.js:

    var snatchImage = function (req, res){
        var html = res.render('snatchImage',
            {
                title: 'Hey',
                message: 'Hello there!'
            });
        return res.send(html);
    };

    exports.snatch = snatchImage;

这是PUG文件:

    doctype html5
    html
        head
            title= title
            link(rel='stylesheet', href='/css/style.css')
        body
            div(rel='stylesheet', href='/style.css', class="selection")= message

如果我错过了这里的东西是git,也许会更清楚地看到它。 Git link

0 个答案:

没有答案