本文介绍了Node.js - express - jade - 编译SASS / LESS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都有一个真的新手指南nodejs - express - SASS / LESS?我没能得到这个工作。我现在的例子是可以实现的。

Anyone have a really newbie guide to nodejs - express - SASS/LESS? I have not been able to get this working. The example I have now is a bareboned as possible..

var express = require('express'),
    less = require('less'),
    app = express.createServer();

var pub_dir = __dirname + '/public';

app.configure(function(){
    app.use(express.compiler({ src: pub_dir, enable: ['less'] }));
    app.use(express.staticProvider( pub_dir ));
};

app.configure('development', function(){
    app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

文件 style.css.less 位于 pub_dir 中,我可以直接访问,样式是

The file style.css.less is located in pub_dir, I can access that directly, and the styling is

@brand_color: #4D926F;
body {
  color: @brand_color;
}

据了解,编译应该在启动时发生,并且css文件将在 src -dir,因为没有指定dest。

我的服务器运行正常,但无论我尝试使用dirnames,目录和LESS / SASS文件的名称(以及它们各自的LESS / SASS内容)我不能得到这个工作Darn!H elp。

As far as I understand, the compilation is supposed to happen on start-up, and a css file will be generated in the src-dir, as dest is not specified.
My server runs fine, but regardless of how many ways I have tried messing around with the dirnames, directories and names of the LESS/SASS files (and their respective LESS/SASS content) I cannot get this working. Darn! Help.

推荐答案

我也是一个尝试获取此设置的新手。我已经尝试了一些我发现的片段,直到我终于注意到,express有一个'express'命令设置一个新的项目。

I'm also a newb trying to get this setup. I have tried a few snippets I found until I finally noticed that express has an 'express' command that sets up a new project.

尝试 express -c less 创建一个带有LESS作为CSS引擎的示例项目。

Try express -c less to create a sample project with LESS as the CSS engine.

这应该创建所需的目录。新的css文件将从您的静态目录中提供。

This should create the required directories. The new css files will be served from your static directory.

配置为:

app.configure(function(){
  app.set('views', __dirname + '/views');
  app.set('view engine', 'hbs');
  app.use(express.bodyDecoder());
  app.use(express.methodOverride());
  app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] }));
  app.use(app.router);
  app.use(express.staticProvider(__dirname + '/public'));
});

这篇关于Node.js - express - jade - 编译SASS / LESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 07:29