node.js - Express less-middleware not compiling -
can please me css compiling. don't know why view not getting compiled less
index.js
// middleware var express = require('express'); var less = require('less-middleware'); var app = express(); // less compiler app.use(less('source/less', { "dest": 'public/stylesheets', "pathroot": __dirname, "force": true, "render": { "yuicompress": true } })); // app config app.use(express.static(__dirname + '/public')); app.set('views', 'views') app.set('view engine', 'jade'); // routes app.get('/', function (req, res) { res.render('index'); }); // page not found app.use(function(req, res, next) { res.status(404).send('sorry cant find that!'); }); // web server var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('example app listening @ http://%s:%s', host, port); });
index.jade
html head title hello link(src="stylesheets/global.css" type="text/css") body h1 welcome
you can read how set src , dest dirs less-middleware different directories @ https://github.com/emberfeather/less.js-middleware/wiki/examples. upshot this: keep things relatively straightforward, relative path of source , dest must identical.
i recommend moving less source files out of public
make easier , because they're not supposed served as-is anyway.
create less-src
dir in same directory has public
directory. inside less-src
, create stylesheets
directory , put global.less
in there. change less middleware use this:
app.use(lessmiddleware(__dirname + '/less-src', {dest: __dirname + '/public'}));
and work.
if dislike having stylesheets
directory in less-src
, need @ material preprocessing less path @ the link above. me, trades code complexity little gain in terms of source code layout. if seems worth you, that's how can it.
Comments
Post a Comment