-
-
Notifications
You must be signed in to change notification settings - Fork 780
/
build.mjs
58 lines (48 loc) · 1.2 KB
/
build.mjs
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
/* eslint-disable no-console */
import { performance } from 'perf_hooks'
import { join } from 'pathe'
import fs from 'fs-extra'
import { build } from 'vite'
import { dir, targets } from './meta.mjs'
const result = {}
const date = new Date().toISOString()
function BuildTimePlugin(name) {
let start = 0
return {
name: 'time-log',
apply: 'build',
buildStart() {
start = performance.now()
},
closeBundle() {
result[name].time = performance.now() - start
},
}
}
console.log('warming up...')
for (let i = 0; i < 10; i++)
await run('none')
targets.sort(() => Math.random() - 0.5)
for (let i = 0; i < targets.length; i++) {
const name = targets[i]
console.log(`- ${name}`)
result[name] = { index: i, name, date }
await run(name, true)
}
async function run(target, bench = false) {
const cwd = join(dir, 'fixtures', target)
process.chdir(cwd)
await build({
root: cwd,
logLevel: 'silent',
build: {
minify: false,
},
plugins: bench
? [BuildTimePlugin(target)]
: [],
})
}
const full = await fs.readJSON(`${dir}/result.json`) || []
full.push(...Object.values(result))
await fs.writeJSON(`${dir}/result.json`, full, { spaces: 2 })