Skip to content

Commit 680eef3

Browse files
committed
plugin: add vite-bundle-analyzer support to build commands
1 parent 68d6cdb commit 680eef3

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@vitejs/plugin-react": "5.1.2",
3737
"jsdom": "27.3.0",
3838
"sass": "1.96.0",
39+
"vite-bundle-analyzer": "^1.3.2",
3940
"vite-plugin-static-copy": "3.1.4",
4041
"vite-tsconfig-paths": "*",
4142
"vitest": "4.0.15"
@@ -46,4 +47,4 @@
4647
"overrides": {
4748
"rollup": "4.44.2"
4849
}
49-
}
50+
}

plugin/vite.config.mts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import replace from "@rollup/plugin-replace";
22
import react from "@vitejs/plugin-react";
3-
import { loadEnv } from "vite";
3+
import { loadEnv, type PluginOption } from "vite";
4+
import { analyzer } from "vite-bundle-analyzer";
45
import { viteStaticCopy } from "vite-plugin-static-copy";
56
import tsConfigPaths from "vite-tsconfig-paths";
67
import { configDefaults, defineConfig } from "vitest/config";
@@ -35,6 +36,19 @@ function getShouldMinify(): boolean {
3536
return env?.VITE_ENV !== "dev";
3637
}
3738

39+
function bundleAnalyzerPlugin(): PluginOption {
40+
const mode = process.env.VITE_BUNDLE_ANALYZER_MODE;
41+
if (mode === "server" || mode === "static" || mode === "json") {
42+
return analyzer({ analyzerMode: mode });
43+
}
44+
45+
if (mode !== undefined) {
46+
throw new Error(`Invalid VITE_BUNDLE_ANALYZER_MODE: ${mode}`);
47+
}
48+
49+
return undefined;
50+
}
51+
3852
export default defineConfig({
3953
plugins: [
4054
react(),
@@ -51,6 +65,7 @@ export default defineConfig({
5165
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
5266
SYNC_WITH_TODOIST_BUILD_STAMP: getBuildStamp(),
5367
}),
68+
bundleAnalyzerPlugin(),
5469
],
5570
build: {
5671
// We aren't building a website, so we build in library mode

0 commit comments

Comments
 (0)