如何使用Express安装SASS?

ily*_*lyo 23 sass node.js express

我正在使用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
  });
});
Run Code Online (Sandbox Code Playgroud)

但它仍然无效

sou*_*eck 26

您需要使用sass中间件,例如这个.

从文档引用:

var server = connect.createServer(
   sass.middleware({
       src: __dirname
       , dest: __dirname + '/public'
       , debug: true
    }),
   connect.static(__dirname + '/public')
);
Run Code Online (Sandbox Code Playgroud)

如果使用快递,只需添加:

 app.use(
     sass.middleware({
         src: __dirname + '/sass', //where the sass files are 
         dest: __dirname + '/public', //where css should go
         debug: true // obvious
     })
 );
Run Code Online (Sandbox Code Playgroud)

给你app.configure()打电话.

当然在生产系统上,将sass预编译为css是一个更好的主意.

更新

在上面的示例中,中间件将查找sass文件__dirname + '/sass/css'.默认情况下,它会查找具有.scss扩展名的文件.似乎没有更改扩展名的选项.

  • 在`app.configure`调用内或您配置中间件的任何地方 (2认同)

小智 9

如果您使用快速发电机然后尝试

express --view=ejs --css=sass
Run Code Online (Sandbox Code Playgroud)