-
Notifications
You must be signed in to change notification settings - Fork 188
/
test.js
78 lines (73 loc) · 1.57 KB
/
test.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const css = require('./');
const fs = require('fs');
if (process.argv[process.argv.length - 1] !== __filename) {
let opts = {
filename: process.argv[process.argv.length - 1],
code: fs.readFileSync(process.argv[process.argv.length - 1]),
minify: true,
sourceMap: true,
targets: {
chrome: 95 << 16
}
};
console.time('optimize');
let r = css.transform(opts);
console.timeEnd('optimize')
// console.log(r.toString());
console.log(r);
let code = r.code;
if (r.map) {
code = code.toString() + `\n/*# sourceMappingURL=out.css.map */\n`;
}
fs.writeFileSync('out.css', code);
if (r.map) {
fs.writeFileSync('out.css.map', r.map);
}
return;
}
let res = css.transform({
filename: __filename,
code: Buffer.from(`
@breakpoints {
.foo { color: yellow; }
}
.foo {
color: red;
@bar {
width: 25px;
}
}
`),
drafts: {
nesting: true
},
targets: {
safari: 16 << 16
},
customAtRules: {
breakpoints: {
// Syntax string defining the at rule prelude.
// https://drafts.css-houdini.org/css-properties-values-api/#syntax-strings
prelude: null,
// Type of the at rule block.
// Can be declaration-list, rule-list, or style-block.
// https://www.w3.org/TR/css-syntax-3/#declaration-rule-list
body: 'rule-list'
},
bar: {
body: 'style-block'
}
},
visitor: {
Rule: {
custom(rule) {
console.log(rule.body);
}
},
Length(length) {
length.value *= 2;
return length;
}
}
});
console.log(res.code.toString());