Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use "kB" everywhere with the correct definition #14061

Merged
merged 3 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/guide/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ Running `vite build` with this config uses a Rollup preset that is oriented towa
```
$ vite build
building for production...
dist/my-lib.js 0.08 KiB / gzip: 0.07 KiB
dist/my-lib.umd.cjs 0.30 KiB / gzip: 0.16 KiB
dist/my-lib.js 0.08 kB / gzip: 0.07 kB
dist/my-lib.umd.cjs 0.30 kB / gzip: 0.16 kB
```

Recommended `package.json` for your lib:
Expand Down
8 changes: 4 additions & 4 deletions packages/vite/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function createCjsConfig(isProduction: boolean) {
...Object.keys(pkg.dependencies),
...(isProduction ? [] : Object.keys(pkg.devDependencies)),
],
plugins: [...createNodePlugins(false, false, false), bundleSizeLimit(120)],
plugins: [...createNodePlugins(false, false, false), bundleSizeLimit(123)],
})
}

Expand Down Expand Up @@ -317,7 +317,7 @@ const __require = require;
/**
* Guard the bundle size
*
* @param limit size in KB
* @param limit size in kB
*/
function bundleSizeLimit(limit: number): Plugin {
return {
Expand All @@ -329,10 +329,10 @@ function bundleSizeLimit(limit: number): Plugin {
.join(''),
'utf-8',
)
const kb = size / 1024
const kb = size / 1000
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this change triggered the limit 😅

packages/vite build: [!] (plugin bundle-limit) Error: Bundle size exceeded 120 kB, current size is 121.86kb.
packages/vite build:     at Object.generateBundle (file:///home/runner/work/vite/vite/packages/vite/rollup.config-1691641081524.mjs:360:23)
packages/vite build:     at /home/runner/work/vite/vite/node_modules/.pnpm/rollup@3.28.0/node_modules/rollup/dist/shared/rollup.js:1909:40
packages/vite build:  ELIFECYCLE  Command failed with exit code 1.
packages/vite build: ERROR: "build-bundle" exited with 1.
packages/vite build: Failed

Copy link
Contributor Author

@naruaway naruaway Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous limit was actually 120 kiB, which is 122880 bytes = 122.88 kB

I think 123 kB seems reasonable approximation assuming we do not want to put weird number 122.88 in the config. Now I did the change in 3b4904f

if (kb > limit) {
throw new Error(
`Bundle size exceeded ${limit}kb, current size is ${kb.toFixed(
`Bundle size exceeded ${limit} kB, current size is ${kb.toFixed(
2,
)}kb.`,
)
Expand Down
2 changes: 1 addition & 1 deletion playground/assets/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default defineConfig({
assetsInclude: ['**/*.unknown'],
build: {
outDir: 'dist/foo',
assetsInlineLimit: 8192, // 8kb
assetsInlineLimit: 8000, // 8 kB
manifest: true,
watch: {},
},
Expand Down
Loading