Node-Sass |除非我手动删除css文件,否则不重新编译

前端之家收集整理的这篇文章主要介绍了Node-Sass |除非我手动删除css文件,否则不重新编译前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我刚刚开始使用node-sass.我已经到了我要求style.css的地步.如果我的stylesheets目录中没有style.css,那么它会为我编译它,但是一旦编译它就不会更新/重新编译更改,直到我手动删除css文件. @H_404_2@任何有关这方面的帮助将非常感激.

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

解决方法

您需要切换静态和SASS中间件的声明(也就是说,静态中间件应该在sass中间件之后 – 有关更多信息,请参阅 this answer):
// 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')));
@H_404_2@否则,当您请求CSS文件并且它已经存在时,静态中间件将处理它并且请求将永远不会到达SASS中间件.

原文链接:https://www.f2er.com/css/242372.html

猜你在找的CSS相关文章