Node-Sass | Do not recompile unless I manually delete the css file

I'm just starting to use node-sass. I have this to such an extent that I am requesting style.css. If I do not have style.css style in my styles directory, it compiles it for me, however after compiling it it will not update / recompile the changes until I delete the css files manually.

Any help with this would be greatly appreciated.

app.js

/** * Module dependencies. */ var express = require('express'); var routes = require('./routes'); var user = require('./routes/user'); var http = require('http'); var path = require('path'); var sass = require('node-sass'); var app = express(); // all environments app.set('port', process.env.PORT || 3000); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.json()); app.use(express.urlencoded()); app.use(express.methodOverride()); app.use(app.router); app.use(express.static(path.join(__dirname, 'public'))); app.use( sass.middleware({ src: __dirname + '/public/sass', //where the sass files are dest: __dirname + '/public', //where css should go debug: true, // obvious outputStyle: 'compressed' }) ); app.use(express.static(path.join(__dirname, 'public'))); // development only if ('development' == app.get('env')) { app.use(express.errorHandler()); } app.get('/', routes.index); app.get('/users', user.list); http.createServer(app).listen(app.get('port'), function(){ console.log('Express server listening on port ' + app.get('port')); }); 
+6
source share
1 answer

You need to switch the static and middleware SASS declarations (i.e. static middleware should appear after the sass middleware - see this answer for more information):

 // Notice we are removing this line: // app.use(express.static(path.join(__dirname, 'public'))); app.use( sass.middleware({ src: __dirname + '/public/sass', //where the sass files are dest: __dirname + '/public', //where css should go debug: true, // obvious outputStyle: 'compressed' }) ); app.use(express.static(path.join(__dirname, 'public'))); 

Otherwise, when you request the CSS file and it already exists, the static middleware will process it and the request will never reach the SASS middleware.

+6
source

All Articles