lighting-plugin-less
Advanced tools
+16
-18
@@ -12,23 +12,21 @@ var less = require("less"); | ||
| prepare:function (light,cb) { | ||
| var files = light.util.glob.sync("dist/**/*.less"); | ||
| var filesLength = files.length; | ||
| if(filesLength==0) return cb(); | ||
| let files = light.util.glob.sync("dist/**/*.less"), | ||
| processPromise = []; | ||
| files.forEach(function (file) { | ||
| var str = light.util.readFileSync(file).toString(); | ||
| processPromise.push(new Promise(function (resolve, reject) { | ||
| less.render(light.util.readFileSync(file).toString(),{ | ||
| path: light.util.parse(file).dir | ||
| }, function(err, result) { | ||
| light.util.writeFileSync(file.replace(/less$/i,"css"),result.css); | ||
| resolve() | ||
| }); | ||
| })); | ||
| }); | ||
| less.render(str,{ | ||
| paths:light.util.parse(file).dir | ||
| }, function(e, r) { | ||
| filesLength--; | ||
| if(!e){ | ||
| light.util.writeFileSync(file,r.css); | ||
| light.util.renameSync(file,file.replace(/less$/i,"css")); | ||
| }else{ | ||
| light.util.log("error","less插件执行错误:"+e); | ||
| } | ||
| if(filesLength==0) cb(); | ||
| }); | ||
| }) | ||
| Promise.all(processPromise).then(function () { | ||
| light.util.glob.sync("dist/**/*.less").forEach(function (file) { | ||
| light.util.removeSync(file); | ||
| }) | ||
| }).then(cb); | ||
| }, | ||
@@ -35,0 +33,0 @@ |
+1
-1
| { | ||
| "name": "lighting-plugin-less", | ||
| "version": "1.0.4", | ||
| "version": "1.0.5", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
1440
1.62%41
-2.38%