forked from parcel-bundler/lightningcss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.js
45 lines (39 loc) · 1.03 KB
/
bench.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
const css = require('./');
const cssnano = require('cssnano');
const postcss = require('postcss');
const esbuild = require('esbuild');
let opts = {
filename: process.argv[process.argv.length - 1],
code: require('fs').readFileSync(process.argv[process.argv.length - 1]),
minify: true,
// source_map: true,
targets: {
chrome: 95 << 16
}
};
async function run() {
await doCssNano();
console.time('esbuild');
let r = await esbuild.transform(opts.code.toString(), {
sourcefile: opts.filename,
loader: 'css',
minify: true
});
console.timeEnd('esbuild');
console.log(r.code.length + ' bytes');
console.log('');
console.time('lightningcss');
let res = css.transform(opts);
console.timeEnd('lightningcss');
console.log(res.code.length + ' bytes');
}
async function doCssNano() {
console.time('cssnano');
const result = await postcss([
cssnano,
]).process(opts.code, {from: opts.filename});
console.timeEnd('cssnano');
console.log(result.css.length + ' bytes');
console.log('');
}
run();