Skip to content

Commit

Permalink
Optimize vite build (#1193)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev authored Dec 19, 2024
1 parent 5871833 commit 0dadaa9
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/keychain/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ dist-ssr
*.njsproj
*.sln
*.sw?
stats.html
1 change: 1 addition & 0 deletions packages/keychain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"playwright": "^1.47.1",
"postcss": "^8.4.35",
"prettier": "^2.7.1",
"rollup-plugin-visualizer": "^5.12.0",
"storybook": "^8.2.9",
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5",
Expand Down
34 changes: 34 additions & 0 deletions packages/keychain/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import react from "@vitejs/plugin-react-swc";
import wasm from "vite-plugin-wasm";
import topLevelAwait from "vite-plugin-top-level-await";
import { nodePolyfills } from "vite-plugin-node-polyfills";
import { visualizer } from "rollup-plugin-visualizer";

export default defineConfig(({ mode }) => ({
plugins: [
Expand All @@ -15,6 +16,13 @@ export default defineConfig(({ mode }) => ({
wasm(),
topLevelAwait(),
react(),
// Add visualizer in build mode
mode === "production" &&
visualizer({
open: true,
gzipSize: true,
brotliSize: true,
}),
],
server: {
port: mode === "development" ? 3001 : undefined,
Expand All @@ -29,6 +37,32 @@ export default defineConfig(({ mode }) => ({
build: {
rollupOptions: {
external: ["vite-plugin-node-polyfills/shims/global"],
output: {
manualChunks(id) {
// Chunk splitting logic
if (id.includes("node_modules")) {
if (id.includes("react")) {
return "react-vendor";
}
// Split other large dependencies into separate chunks
return "vendor";
}
},
},
},
target: "esnext",
minify: "esbuild", // esbuild is faster than terser and almost as effective
sourcemap: mode === "development",
// Reduce chunk size warnings and enable compression reporting
chunkSizeWarningLimit: 1000,
reportCompressedSize: true,
// Optimize build speed and output
cssCodeSplit: true,
modulePreload: {
polyfill: false, // Reduces polyfill size if you don't need older browser support
},
},
optimizeDeps: {
include: ["react", "react-dom"], // Pre-bundle common dependencies
},
}));
28 changes: 28 additions & 0 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 0dadaa9

Please sign in to comment.