-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (33 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
module.exports = function(options) {
options = options || {};
return {
postcssPlugin: 'postcss-george',
prepare(result) {
const values = Object.create(null);
let exportNext = false;
return {
Comment(comment) {
if (comment.text.match(/\@export/)) {
exportNext = true;
if (options.stripGeorgeComments) {
comment.remove();
}
}
},
Declaration(decl) {
if (exportNext && decl.variable && decl.prop.substring(2) !== '') {
values[decl.prop.substring(2)] = decl.value;
}
exportNext = false;
},
OnceExit(root, { Comment }) {
const b64Map = Buffer.from(JSON.stringify(values)).toString('base64');
root.append(new Comment({
text: `# georgeMappingURL=data:application/json;charset=utf-8;base64,${b64Map}`
}));
}
};
}
};
};
module.exports.postcss = true;