node-sass-middleware不能编译

我试图让快递节点与sass中间件一起工作。 该应用程序运行没有错误

...(modules) var sassMiddleware = require('node-sass-middleware'); var routes = require('./routes/index'); var app = express(); // uncomment after placing your favicon in /public //app.use(favicon(__dirname + '/public/favicon.ico')); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); //---- LOAD SASS -----// // adding the sass middleware var srcPath = __dirname + '/scss'; var destPath = __dirname + '/public/stylesheets'; app.use(sassMiddleware({ src: srcPath, dest: destPath, debug: true, outputStyle: 'compressed' })); app.use(express.static(path.join(__dirname, 'public'))); 

任何人都可以看到我试图编译sass的方式有什么问题吗?

文件结构:

 app controllers routes public -stylesheets scss ... 

这就是app.js应该是这样的:

 app.use(sassMiddleware({ src: srcPath, dest: destPath, debug: true, outputStyle: 'compressed' }), express.static(path.join(__dirname, 'public'))); 

另外你的主scss文件应该被命名为style.scss,并且位于scss / stylesheets /目录中。

你应该看到这样的日志,如果你已经正确地加载模块:

  source : /Users/abc/Desktop/SO/SO_node/scss/stylesheets/style.scss dest : /Users/abc/Desktop/SO/SO_node/public/stylesheets/stylesheets/style.css read : /Users/abc/Desktop/SO/SO_node/public/stylesheets/stylesheets/style.css render : /Users/abc/Desktop/SO/SO_node/scss/stylesheets/style.scss 

一个问题也可能是你想编译scss

而不是sass 。 因此将indentedSyntax设置为false

 app.use(require('node-sass-middleware')({ src: path.join(__dirname, 'scss'), dest: path.join(__dirname, 'public'), indentedSyntax : false, sourceMap: true })); 

或完全删除它。 Express-generator在默认情况下添加此值。

最好去咕噜咕噜 。 简单的configuration,自动化的任务(感谢grunt)以及更快的编译时间,因为libsass是SASS的原始Ruby编译器的C版本。 编译sass / scss文件在0.3秒而不是3。