forked from fouber/fis-parser-less
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (40 loc) · 1.21 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* fis
* http://fis.baidu.com/
*/
'use strict';
var less = require('less');
var root = fis.project.getProjectPath();
module.exports = function(content, file, conf) {
conf.paths = [file.dirname, root];
conf.syncImport = true;
/* 参考
https://github.com/gruntjs/grunt-contrib-less/blob/master/README.md
Source Map Revision 3 proposal
https://docs.google.com/a/google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
Working with CSS Preprocessors
https://developer.chrome.com/devtools/docs/css-preprocessors
*/
conf.filename = '/source' + file.subpath; // *.map {sources: '此处用到'}
conf.sourceMap = true;
conf.sourceMapFilename = file.filename + '.map';
conf.sourceMapURL = file.filename + '.map';
conf.writeSourceMap = function(sourceMapContent) {
var fs = require('fs');
fs.writeFileSync(file.dirname + '/' + file.filename + '.map', sourceMapContent, null);
};
var parser = new(less.Parser)(conf);
parser.parse(content, function(err, tree) {
if (err) {
throw err;
} else {
if (parser.imports) {
fis.util.map(parser.imports.files, function(path) {
file.cache.addDeps(path);
});
}
content = tree.toCSS(conf);
}
});
return content;
};