-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
prefixers.js
110 lines (101 loc) · 2.66 KB
/
prefixers.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* Results on Node 20.3.1, Github Actions:
Lightning CSS: 12 ms (7.7 times faster)
Stylis: 18 ms (5.3 times faster)
Autoprefixer: 96 ms
Stylecow: 1009 ms (10.5 times slower)
*/
let { existsSync, readFileSync } = require('node:fs')
let stylecowPrefixes = require('stylecow-plugin-prefixes')
let autoprefixer = require('autoprefixer')
let browserslist = require('browserslist')
let lightning = require('lightningcss')
let stylecow = require('stylecow-core')
let { join } = require('node:path')
let postcss = require('postcss')
let stylis = require('stylis')
let example = join(__dirname, 'cache', 'bootstrap.css')
let origin = readFileSync(example).toString()
let browsers = browserslist('defaults')
// Autoprefixer
let cleaner = postcss([autoprefixer({ overrideBrowserslist: [] })])
let css = cleaner.process(origin, { from: example }).css
let processor = postcss([autoprefixer({ overrideBrowserslist: browsers })])
// Stylecow
let stylecowOut = new stylecow.Coder()
let stylecower = new stylecow.Tasks()
stylecower.use(stylecowPrefixes)
// Lightning
let lightningBrowsers = lightning.browserslistToTargets(browsers)
let cssBuffer = Buffer.from(css)
module.exports = {
maxTime: 15,
name: 'Prefixers',
tests: [
{
fn: () => {
stylis.serialize(
stylis.compile(css),
stylis.middleware([stylis.prefixer, stylis.stringify])
)
},
name: 'Stylis'
},
{
defer: true,
fn: done => {
processor
.process(css, {
from: example,
map: false
})
.then(() => {
done.resolve()
})
},
name: 'Autoprefixer'
},
{
fn: () => {
lightning.transform({
code: cssBuffer,
filename: example,
minify: false,
sourceMap: false,
targets: lightningBrowsers
})
},
name: 'Lightning CSS'
},
{
defer: true,
fn: done => {
let code = stylecow.parse(css)
stylecower.run(code)
stylecowOut.run(code)
done.resolve()
},
name: 'Stylecow'
}
]
}
let devA = join(__dirname, '../autoprefixer/lib/autoprefixer.js')
let devP = join(__dirname, '../postcss/lib/postcss.js')
if (existsSync(devA) && existsSync(devP)) {
let devAutoprefixer = require(devA)
let devPostcss = require(devP)
let devProcessor = devPostcss([devAutoprefixer])
module.exports.tests.splice(0, 0, {
defer: true,
fn: done => {
devProcessor
.process(css, {
from: example,
map: false
})
.then(() => {
done.resolve()
})
},
name: 'Autoprefixer dev'
})
}