我们从去年5月开始做小程序项目,经过一年的迭代,功能已经很完善了。。。差远了。西内刚开始开发的时候,是用wxss写样式代码的,那个效率,PM差点气得辞职。于是我们开始寻找高效的方案(找个屁,百度搜了一堆),网上很多方案都是在编辑器里配置的,emmmmm这个真是高效。由于实在不习惯改编辑器配置,所以还是写了个脚本来less编译。(老表,直接上代码,BB真多)。一种是用lessc编译,一种是用less的render方法;尽量不要在小程序中引入本地的less包,所以lessc/less都是在全局环境下使用的(该死的)。github地址:node-compile-less希望给予鼓励,谢谢/***@fileappletcompileless**/constfs=require('fs');constpath=require('path');//constless=require('less');const{exec}=require('child_process');constglobalLessc='/Users/yujinjiang/.nvm/versions/node/v14.4.0/bin/lessc';//编译配置constCOMPILE_CONFIG={SOURCE:'less',TARGET:'wxss'};//编译目录constobservedDirs=[path.join(__dirname,'./pages/'),path.join(__dirname,'./packageA/'),path.join(__dirname,'./components/'),];//编译和监控observedDirs.forEach(observedDir=>{//监控选项constwatchOptions={persistent:true,recursive:true,encoding:'utf-8'};fs.watch(observedDir,watchOptions,(eventType,filename)=>{constext=filename.slice(filename.lastIndexOf('.')+1);const{SOURCE,TARGET}=COMPILE_CONFIG;如果(ext===SOURCE){constsourcePath=path.join(observedDir,文件名);consttargetPath=sourcePath.slice(0,sourcePath.lastIndexOf('.')+1)+TARGET;exec(`${globalLessc}${sourcePath}${targetPath}`);//constencodingOption={//编码:'utf-8'//};//fs.readFile(//sourcePath,//encodingOption,//(e,data)=>{//if(e){//return;//}////less.render(data)//.then(code=>{////fs.writeFile(//targetPath,//code.css,//encodingOption,//(e)=>{//如果(e){//console.log(e);//}//}//);//})//.catch(()=>{});//}//);}});});
