如何使用 Express 安装 SASS? [英] How do you install SASS with Express?
问题描述
我正在使用 Express 和 socket.io 创建一个 node.js 应用程序.我想使用 SASS,我看到有一个 npm 包,我不明白如何在 SASS npm 和应用程序之间进行链接并使其解析 SASS?
I am creating a node.js app with Express and socket.io. I want to use SASS and I see there is a npm package for it, what I don't understand is how do I link between the SASS npm and the app and make it parse the SASS?
更新:我使用了 SASS 中间件 https://github.com/andrew/node-sass 安装它并以下列方式包含它:
UPDATE: I used SASS middleware https://github.com/andrew/node-sass installed it and included it the following way:
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中间件,例如这个.
You need to use the sass middleware, for example this one.
引自文档:
var server = connect.createServer(
sass.middleware({
src: __dirname
, dest: __dirname + '/public'
, debug: true
}),
connect.static(__dirname + '/public')
);
如果使用express,只需添加:
in case of using express, just add:
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.
Of course on production systems it's a better idea to precompile sass to css.
更新
在上面的示例中,中间件将在 __dirname + '/sass/css'
中查找 sass
文件.此外,默认情况下,它会查找带有 .scss
扩展名的文件.似乎没有更改扩展名的选项.
In the example above the middleware will look for sass
files in __dirname + '/sass/css'
. Also by default it looks for files with .scss
extension. There doesn't seem to be an option to change the extension.
这篇关于如何使用 Express 安装 SASS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!