码迷,mamicode.com
首页 > 其他好文 > 详细

Node环境下实现less编译

时间:2015-06-17 19:46:42      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

今天在学习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%) }}‘;

  

Node环境下实现less编译

标签:

原文地址:http://www.cnblogs.com/rainheader/p/4584048.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!