-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathcheck-size.mjs
44 lines (41 loc) · 1.19 KB
/
check-size.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
import fs from 'node:fs/promises'
import path from 'node:path'
import chalk from 'chalk'
import { gzipSync } from 'zlib'
import { compress } from 'brotli'
const __dirname = path.dirname(new URL(import.meta.url).pathname)
async function checkFileSize(filePath) {
const stat = await fs.stat(filePath).catch(() => null)
if (!stat?.isFile()) {
console.error(chalk.red(`File ${chalk.bold(filePath)} not found`))
return
}
const file = await fs.readFile(filePath)
const minSize = (file.length / 1024).toFixed(2) + 'kb'
const [gzipped, compressed] = await Promise.all([
gzipSync(file),
//
compress(file),
])
const gzippedSize = (gzipped.length / 1024).toFixed(2) + 'kb'
const compressedSize = (compressed.length / 1024).toFixed(2) + 'kb'
console.log(
`${chalk.gray(
chalk.bold(path.basename(filePath))
)} min:${minSize} / gzip:${gzippedSize} / brotli:${compressedSize}`
)
}
;(async () => {
await Promise.all(
[
path.resolve(
__dirname,
'../packages/router/size-checks/dist/webRouter.js'
),
path.resolve(
__dirname,
'../packages/router/dist/vue-router.global.prod.js'
),
].map(checkFileSize)
)
})()