check-bundle-size.ts
This file
Path
perf-measures/bundle-check/scripts/check-bundle-size.ts
52 lines · 1.1 KiB · TypeScript
Last changed by
chore: let oxfmt sort imports instead of eslint (#5442)Yusuke Wadabefore adoption859e2c2
History of this fileTake it
The walk stopped after 200 commits: lines older than f0b094d point at it.
Merge commit from forkYusuke Wadabefore adoptionf0b094d
lines 1–3why, one step back1import * as fs from 'node:fs'2import * as os from 'os'3import * as path from 'path'chore: let oxfmt sort imports instead of eslint (#5442)Yusuke Wadabefore adoption859e2c2
line 4why, one step back4import * as esbuild from 'esbuild'Merge commit from forkYusuke Wadabefore adoptionf0b094d
lines 5–52why, one step back56async function main() {7 const tempDir = os.tmpdir()8 const tempFilePath = path.join(tempDir, 'bundle.tmp.js')910 try {11 await esbuild.build({12 entryPoints: ['dist/index.js'],13 bundle: true,14 minify: true,15 format: 'esm' as esbuild.Format,16 target: 'es2022',17 outfile: tempFilePath,18 })1920 const bundleSize = fs.statSync(tempFilePath).size21 const metrics = []2223 metrics.push({24 key: 'bundle-size-b',25 name: 'Bundle Size (B)',26 value: bundleSize,27 unit: 'B',28 })2930 metrics.push({31 key: 'bundle-size-kb',32 name: 'Bundle Size (KB)',33 value: parseFloat((bundleSize / 1024).toFixed(2)),34 unit: 'K',35 })3637 const benchmark = {38 key: 'bundle-size-check',39 name: 'Bundle size check',40 metrics,41 }42 console.log(JSON.stringify(benchmark, null, 2))43 } catch (error) {44 console.error('Build failed:', error)45 } finally {46 if (fs.existsSync(tempFilePath)) {47 fs.unlinkSync(tempFilePath)48 }49 }50}5152main()