mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 19:33:11 +02:00
Switch key areas to lazily import to improve Vite chunk size (#6278)
# Description of Changes Vite currently warns that when it's bundling our code that the chunk size is way too high because most of the imports are static so it can't split them into smaller chunks. This PR changes a few key areas to use lazy imports to try and make the chunks as small as possible with minimal code changes. Vite's warnings kick in at minified chunks being >500kB, and we've got a little way to go still to reach that, but we can keep chipping away at this and I'd rather get the biggest wins done now. I've also included Lighthouse scores because there's been discussion about improving ours recently. It's not the aim of this PR to improve it, but it's nice that it makes it a little better. ## Current main chunks Build split into 12 chunks. Largest chunk in build is: ``` [frontend:build] dist/assets/index-B6JiWDxZ.js 5,175.51 kB │ gzip: 1,495.85 kB ``` <img width="1442" height="775" alt="image" src="https://github.com/user-attachments/assets/b0e8a3fa-4ef3-4ccd-8c1d-bfed2d99bd27" /> Lighthouse score: <img width="423" height="146" alt="before" src="https://github.com/user-attachments/assets/c62056e8-2e77-49a6-a1ae-f08ec8021fb3" /> ## This PR's chunks Build split into 176 chunks. Largest chunk in build is: ``` [frontend:build] dist/assets/index-qCgeCY4B.js 2,878.54 kB │ gzip: 861.03 kB ``` <img width="1447" height="776" alt="image" src="https://github.com/user-attachments/assets/8d0c3cf0-cc25-41c3-b114-4940d3e99349" /> Lighthouse score: <img width="402" height="145" alt="after" src="https://github.com/user-attachments/assets/99a26eb3-bd15-4b92-bf22-82b58b458f52" /> --------- Co-authored-by: EthanHealy01 <[email protected]>
This commit is contained in:
co-authored by
EthanHealy01
parent
51f5345151
commit
3fe8adc5cb
+15
-2
@@ -1,4 +1,4 @@
|
||||
import { defineConfig, loadEnv } from "vite";
|
||||
import { defineConfig, loadEnv, type PluginOption } from "vite";
|
||||
import react from "@vitejs/plugin-react-swc";
|
||||
import tsconfigPaths from "vite-tsconfig-paths";
|
||||
import { viteStaticCopy } from "vite-plugin-static-copy";
|
||||
@@ -20,7 +20,7 @@ const TSCONFIG_MAP: Record<BuildMode, string> = {
|
||||
prototypes: "./tsconfig.prototypes.vite.json",
|
||||
};
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
export default defineConfig(async ({ mode }) => {
|
||||
// Load env file based on `mode` in the current working directory.
|
||||
// Set the third parameter to '' to load all env regardless of the
|
||||
// `VITE_` prefix.
|
||||
@@ -55,6 +55,19 @@ export default defineConfig(({ mode }) => {
|
||||
tsconfigPaths({
|
||||
projects: [tsconfigProject],
|
||||
}),
|
||||
// Set ANALYZE=true to emit dist/stats.html (treemap) alongside the
|
||||
// build; rollup-plugin-visualizer is ESM-only so we import dynamically.
|
||||
...(process.env.ANALYZE === "true"
|
||||
? [
|
||||
(await import("rollup-plugin-visualizer")).visualizer({
|
||||
filename: "dist/stats.html",
|
||||
template: "treemap",
|
||||
gzipSize: true,
|
||||
brotliSize: true,
|
||||
emitFile: false,
|
||||
}) as PluginOption,
|
||||
]
|
||||
: []),
|
||||
viteStaticCopy({
|
||||
targets: [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user