Skip to content

Commit 41f0447

Browse files
committed
add bundle size check
1 parent c0e5046 commit 41f0447

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

examples/server/webui/vite.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { viteSingleFile } from 'vite-plugin-singlefile';
33
import path from 'path';
44
import fs from 'fs';
55

6+
const MAX_BUNDLE_SIZE = 1024 * 1024; // only increase when absolutely necessary
7+
68
const GUIDE_FOR_FRONTEND = `
79
<!--
810
This is a single file build of the frontend.
@@ -26,6 +28,13 @@ const BUILD_PLUGINS = [
2628
const outputIndexHtml = path.join(config.build.outDir, 'index.html');
2729
const content = fs.readFileSync(outputIndexHtml, 'utf-8');
2830

31+
if (content.length > MAX_BUNDLE_SIZE) {
32+
throw new Error(
33+
`Bundle size is too large (${Math.ceil(content.length / 1024)} KB).\n` +
34+
`Please reduce the size of the frontend or increase MAX_BUNDLE_SIZE in vite.config.js.\n`,
35+
);
36+
}
37+
2938
const targetOutputFile = path.join(config.build.outDir, '../../public/index.html');
3039
fs.writeFileSync(targetOutputFile, GUIDE_FOR_FRONTEND + '\n' + content);
3140
}

0 commit comments

Comments
 (0)