var fs = require("fs"); var less = require('less'); var path = require('path'); var baseDir = "xxx"; var cssDir = baseDir+"\\css"; var lessDir = baseDir+"\\less"; fs.watch(lessDir,{},function(event, filename){ var extension = path.extname(filename); var basename = path.basename(filename,extension); if(extension!=".less"){ return; } console.log("compile file : "+filename+" "+new Date()); var fileContent = fs.readFileSync(lessDir+"\\"+filename,{encoding:"utf8"}); less.render(fileContent,{ // compress: true, paths: [lessDir] }, function (e, output) { if(e){ console.log(e); return; } var output_path = cssDir+"\\"+basename+".css" // console.log(output.css); // fs.unlinkSync(output_path); fs.writeFileSync(output_path, output.css) }); });
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。