Node.js-express-jade-编译 SASS/LESS
有人有 Nodejs - Express - SASS/LESS 的真正新手指南吗?我无法让这个工作。我现在的例子是尽可能简单的。
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
中,我可以直接访问它,并且样式是
@brand_color: #4D926F;
body {
color: @brand_color;
}
As far据我了解,编译应该在启动时进行,并且将在 src
-dir 中生成一个 css 文件,因为未指定 dest。
我的服务器运行良好,但无论我尝试了多少种方法来弄乱 LESS/SASS 文件的目录名、目录和名称(及其各自的 LESS/SASS 内容),我都无法正常工作。该死!帮助。
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 }));
});
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;
}
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我也是一个试图获得此设置的新手。我尝试了一些发现的片段,直到我终于注意到express有一个“express”命令来设置一个新项目。
尝试
express -c less
创建一个使用 LESS 作为 CSS 引擎的示例项目。这应该创建所需的目录。新的 css 文件将从您的静态目录提供。
配置是:
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.
Try
express -c less
to create a sample project with LESS as the CSS engine.This should create the required directories. The new css files will be served from your static directory.
The configuration is:
您的设置是 readymade 的标准设置。确保您的系统上安装了 less 编译器。
npm install lessjs Readymade
然后将以下内容添加到您的 server.js
app.use(require('readymade').middleware({root: "public"}));
Your setup is the standard setup for readymade. Make sure that less compiler is installed on your system though.
npm install lessjs readymade
And then add the following to your server.js
app.use(require('readymade').middleware({root: "public"}));
这是一个类似的问题:
Node.js + Express.js。如何渲染更少的 css?
您还可以查看 ExpressJS 网站 上的指南
Here's a similar question:
Node.js + Express.js. How to RENDER less css?
you can also check out the guide on the ExpressJS Website
两个可以让您的生活更轻松的项目
Builder:(Java|Coffee)Script 和 (CSS|Less) ) (构建器|捆绑器|打包器|压缩器|合并|检查器)
DocPad:Express.js 应用程序的预处理器提供者和模板赋能者
Two projects which could make your life easier
Buildr: The (Java|Coffee)Script and (CSS|Less) (Builder|Bundler|Packer|Minifier|Merger|Checker)
DocPad: Pre-processor provider and template empowerer for Express.js apps
我正在研究express 4.x并使用SASS。这是我用于样式的片段部分(注意评论):
这是它的要点: http://git .io/Vr9KJA
I'm working on express 4.x and using SASS. Here is a snippet part I'm using for styles (mind the comments):
Here is a gist for it: http://git.io/Vr9KJA