Skip to content

Commit

Permalink
chore: Dump bundle size in a file
Browse files Browse the repository at this point in the history
  • Loading branch information
franky47 committed Jan 30, 2024
1 parent ccb1651 commit 515c609
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
1 change: 0 additions & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"dayjs": "^1.11.10",
"execa": "^8.0.1",
"lucide-react": "^0.298.0",
"next": "14.1.0",
"next-docs-mdx": "^6.0.2",
Expand Down
16 changes: 10 additions & 6 deletions packages/docs/src/app/(pages)/_landing/bundle-size.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { execa } from 'execa'
import fs from 'node:fs/promises'
import path from 'node:path'
import prettyBytes from 'pretty-bytes'

export async function BundleSize() {
const { stdout } = await execa('./node_modules/.bin/size-limit', ['--json'], {
cwd: path.resolve(process.cwd(), '../../packages/nuqs')
})
const [{ size }] = JSON.parse(stdout)
return prettyBytes(size)
const filePath = path.resolve(process.cwd(), '../../packages/nuqs/size.json')
try {
const json = await fs.readFile(filePath, 'utf8')
const [{ size }] = JSON.parse(json)
return prettyBytes(size)
} catch (error) {
console.error(error)
return 'less than 4KB'
}
}
1 change: 1 addition & 0 deletions packages/nuqs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
size.json
1 change: 1 addition & 0 deletions packages/nuqs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"scripts": {
"dev": "tsup --format esm --watch --external=react",
"build": "tsup --clean --external=react",
"postbuild": "size-limit --json > size.json",
"test": "run-p test:*",
"test:types": "tsd",
"test:unit": "vitest run",
Expand Down
37 changes: 33 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 515c609

Please sign in to comment.