Node环境下实现less编译

今天在学习less的时候发现了在node中是可以渲染的,通过调用less的render方法渲染来生成css,所以写了个小Demo。

var less = require('less');
var http = require('http');
http.createServer(function(req,res,err){	
    res.writeHead(200, {'Content-Type': 'text/plain charset=utf-8'});
    less.render(tmp,{compress: true}, function (e, css) {
        name = css['css'];
    });
    res.end(name);
}).listen(8080);

var name = null;
var tmp = '\
@base: #f938ab;\
.box-shadow(@style, @c)when(iscolor(@c)){\
-webkit-box-shadow: @style @c;\
box-shadow: @style @c;\
}\
.box-shadow(@style, @alpha: 50%) when (isnumber(@alpha)) {\
.box-shadow(@style, rgba(0, 0, 0, @alpha));\
}\
.box {\
color: saturate(@base, 5%);\
border-color: lighten(@base, 30%);\
div { .box-shadow(0 0 5px, 30%) }\
}';

  

posted @ 2015-06-17 18:07  Rain-Heart  阅读(561)  评论(0编辑  收藏  举报