我正在使用 Express 和 socket.io 创建一个 node.js 应用程序。 我想使用 SASS,我看到有一个 npm 包,我不明白如何在 SASS npm 和应用程序之间链接并使其解析 SASS?
更新: 我使用了 SASS 中间件 https://github.com/andrew/node-sass安装它并通过以下方式包含它:
sass = require('node-sass');
app.configure(function(){
app.set('port', process.env.PORT || 3000);
/* other stuff */
sass.middleware({
src: __dirname + '/public/stylesheets/sass',
dest: __dirname + '/public/stylesheets',
debug: true
});
});
但是还是不行
最佳答案
您需要使用 sass 中间件,例如 this one .
引用文档:
var server = connect.createServer(
sass.middleware({
src: __dirname
, dest: __dirname + '/public'
, debug: true
}),
connect.static(__dirname + '/public')
);
如果使用express,只需添加:
app.use(
sass.middleware({
src: __dirname + '/sass', //where the sass files are
dest: __dirname + '/public', //where css should go
debug: true // obvious
})
);
到您的 app.configure()
调用。
当然,在生产系统上,最好将 sass 预编译为 css。
更新
在上面的示例中,中间件将在 __dirname + '/sass/css'
中查找 sass
文件。此外,默认情况下,它会查找具有 .scss
扩展名的文件。似乎没有更改扩展名的选项。
关于node.js - 如何使用 Express 安装 SASS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14242536/