Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including and automatically compiling Sass on Express server

So I have a basic Express project set up and I'm using this github project, https://github.com/andrew/node-sass, to be able to use Sass on top of node. This is my app.js currently:

var io = require('socket.io'),
    express = require('express'),
    path = require('path'),
    routes = require('./routes'),
    jquery = require('jquery');


/**
* Create app
*/

var app = express()
  , server = require('http').createServer(app)
  , io = io.listen(server);

/**
* Configure app
*/ 

app.configure(function(){ 
    app.set('port', 8080);
    app.set('views', __dirname + '/views');
    app.set('view engine', 'ejs');
    app.use(express.static(path.join(__dirname, 'public')));
});

What do I need to do to get Sass working and auto recompiling? I can't seem to find any useful info for Express servers specifically.

like image 573
Connor Black Avatar asked Dec 13 '12 08:12

Connor Black


1 Answers

First add this require statement:

var sass = require("node-sass");

and then the following code, in your app.configure block:

...
app.use(sass.middleware({
    src: <your-sass-files-dir>,
    dest: path.join(__dirname, 'public'),
    debug: true
}));
...

But I'm sorry to say that the node-sass library is quite useless at the moment, because the @import's, in your scss files, does not work as it's supposed to... See https://github.com/andrew/node-sass/issues/27 for current status.

UPDATE 2013-10-22: Apparently the issue mentioned above seems to be fixed according to @jonathanconway in the comments below... Though there's still an unanswered comment on the issue from someone that still experiences the error at 2013-09-03

like image 127
joakimbeng Avatar answered Nov 16 '22 02:11

joakimbeng