forked from postcss/benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefixers.js
86 lines (78 loc) · 2.06 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
/* Results on node 10.4.1, Fedora 28, Intel Core i7-8550U, 16 GB RAM and SSD:
Stylis: 9 ms (4.0 times faster)
Autoprefixer: 34 ms
Stylecow: 157 ms (4.6 times slower)
nib: 176 ms (5.1 times slower)
*/
let { existsSync, readFileSync } = require('fs')
let stylecowPrefixes = require('stylecow-plugin-prefixes')
let autoprefixer = require('autoprefixer')
let stylecow = require('stylecow-core')
let { join } = require('path')
let postcss = require('postcss')
let Stylis = require('stylis')
let example = join(__dirname, 'cache', 'bootstrap.css')
let origin = readFileSync(example).toString()
// Autoprefixer
let cleaner = postcss([autoprefixer({ overrideBrowserslist: [] })])
let css = cleaner.process(origin, { from: example }).css
let processor = postcss([autoprefixer])
// Stylecow
let stylecowOut = new stylecow.Coder()
let stylecower = new stylecow.Tasks()
stylecower.use(stylecowPrefixes)
// Stylis
let stylis = new Stylis()
module.exports = {
name: 'Bootstrap',
maxTime: 15,
tests: [
{
name: 'Autoprefixer',
defer: true,
fn: done => {
processor.process(css, {
from: example, map: false
}).then(() => {
done.resolve()
})
}
},
{
name: 'Stylecow',
defer: true,
fn: done => {
let code = stylecow.parse(css)
stylecower.run(code)
stylecowOut.run(code)
done.resolve()
}
},
{
name: 'Stylis',
defer: true,
fn: done => {
stylis('', css)
done.resolve()
}
}
]
}
let devA = join(__dirname, '../autoprefixer/build/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, {
name: 'Autoprefixer dev',
defer: true,
fn: done => {
devProcessor.process(css, {
from: example, map: false
}).then(() => {
done.resolve()
})
}
})
}