如何在Express中安装SASS? [英] How do you install SASS with Express?

查看:86
本文介绍了如何在Express中安装SASS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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')
);

在使用快递的情况下,只需添加:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆