MCPcopy
hub / github.com/vitejs/vite / bundleSizeLimit

Function bundleSizeLimit

packages/vite/rolldown.config.ts:380–408  ·  view source on GitHub ↗

* Guard the bundle size * * @param limit size in kB

(limit: number)

Source from the content-addressed store, hash-verified

378 * @param limit size in kB
379 */
380function bundleSizeLimit(limit: number): Plugin {
381 let size = 0
382
383 return {
384 name: 'bundle-limit',
385 generateBundle(_, bundle) {
386 if (this.meta.watchMode) return
387
388 size = Buffer.byteLength(
389 Object.values(bundle)
390 .map((i) => ('code' in i ? i.code : ''))
391 .join(''),
392 'utf-8',
393 )
394 },
395 closeBundle() {
396 if (this.meta.watchMode) return
397
398 const kb = size / 1000
399 if (kb > limit) {
400 this.error(
401 `Bundle size exceeded ${limit} kB, current size is ${kb.toFixed(
402 2,
403 )}kb.`,
404 )
405 }
406 },
407 }
408}
409
410// #endregion

Callers 1

rolldown.config.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected