如何使用Express安装SASS? [英] How to install SASS with Express?

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

问题描述

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

/ *其他东西* /

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

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