forked from WangJia-mm/JavaScript201708
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLESS.js
More file actions
19 lines (19 loc) · 810 Bytes
/
LESS.js
File metadata and controls
19 lines (19 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//->定义编译文件目录和目标导出目录
var dirPath = "./less/", tarPath = "./css/";
//->导入NODE中需要使用的模块
var fs = require("fs"),
less = require("less");
//->读取dirPath中的所有文件,检查文件的类型,只有LESS文件我们才进行存储
var ary = [],
files = fs.readdirSync(dirPath);
files.forEach(function (file, index) {
/\.(LESS)/i.test(file) ? ary.push(file) : null;
});
//->把目录下的所有文件进行编译,把编译完成的结果保存在指定的目录中
ary.forEach(function (file) {
var newFile = file.replace(".less", ".css"),
conFile = fs.readFileSync(dirPath + file, "utf-8");
less.render(conFile, {compress: true}, function (error, output) {
fs.writeFileSync(tarPath + newFile, output.css, "utf-8");
});
});