如何使用Express安装SASS? [英] How to install SASS with Express?
问题描述
我想使用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);
/ *其他东西* /
sass.middleware({
src:__dirname +'/ public / stylesheets / sass',
dest:__dirname +'/ public / stylesheets' ,
debug:true
});
});
但它仍然不起作用
您需要使用sass中间件,例如这一个一>。
从文档引用:
var server = connect.createServer
sass.middleware({
src:__dirname
,dest:__dirname +'/ public'
,debug:true
}),
connect。 static(__ dirname +'/ public')
);
如果使用快递,只需添加:
app.use(
sass.middleware({
src:__dirname +'/ sass',//其中sass文件是
dest :__dirname +'/ public',//其中css应该去
debug:true //显示
})
);
到您的 app.configure()
。
当然在生产系统上,将sass预编译为css是一个更好的主意。
update
在上面的示例中,中间件将在 __ dirname中查找
。默认情况下,它也会查找具有 sass
+'/ sass / css' .scss
扩展名的文件。似乎没有更改扩展名的选项。
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?
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
});
});
But it still doesn't work
You need to use the sass middleware, for example this one.
Quoting from docs:
var server = connect.createServer(
sass.middleware({
src: __dirname
, dest: __dirname + '/public'
, debug: true
}),
connect.static(__dirname + '/public')
);
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
})
);
to your app.configure()
call.
Of course on production systems it's a better idea to precompile sass to css.
update
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屋!