You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 03-bundling/06-vite/11-bundle-analyzer/README.md
+38-5Lines changed: 38 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,12 +30,12 @@ Install [Node.js and npm](https://nodejs.org/en/) (20.19.0 || >=22.12.0) if they
30
30
>
31
31
> These tools are critical to manually increase application performance before we commit to production, and, therefore, they are usually applied over production bundles only.
32
32
>
33
-
> There are different libraries out there, like `rollup-plugin-visualizer`, `vite-bundle-analyzer`, etc. We will use the first one for this sample.
33
+
> There are different libraries out there, like `vite-bundle-analyzer`, `rollup-plugin-visualizer`, etc. We will use the first one for this sample.
34
34
35
-
-Given these tools are usually plug and play, their usage is as simple as installing it first:
35
+
-These tools are usually plug and play, so their usage is as simple as installing it first:
36
36
37
37
```bash
38
-
npm install rollup-plugin-visualizer --save-dev
38
+
npm install vite-bundle-analyzer --save-dev
39
39
```
40
40
41
41
- And then, use it as a plugin in `vite.config.js`:
@@ -47,14 +47,47 @@ Install [Node.js and npm](https://nodejs.org/en/) (20.19.0 || >=22.12.0) if they
47
47
import checker from "vite-plugin-checker";
48
48
import react from "@vitejs/plugin-react";
49
49
import tailwindcss from "@tailwindcss/vite";
50
-
+ import { visualizer } from "rollup-plugin-visualizer";
50
+
+ import { analyzer } from "vite-bundle-analyzer";
51
51
52
52
export default defineConfig({
53
53
plugins: [
54
54
checker({ typescript: true }),
55
55
tailwindcss(),
56
56
react(),
57
-
+ visualizer(),
57
+
+ analyzer(),
58
58
],
59
59
});
60
60
```
61
+
62
+
- Let's see what we get out-of-the-box:
63
+
64
+
```bash
65
+
npm build
66
+
```
67
+
68
+
🔎 Check how `localhost:8888` is automatically opened after the build is complete. This is the default behaviour of the package.
69
+
70
+
This server renders a report showing an interactive tree map that represents what the the different bundles are made of. It shows every module proportionally to its size.
71
+
72
+
You can also expand a search panel to look for specific modules and check its size under different assumptions (gzipped, brotli, etc).
73
+
74
+
- We can also pass options to the analyzer like:
75
+
76
+
```diff
77
+
react(),
78
+
+ analyzer({
79
+
+ analyzerMode: "static",
80
+
+ openAnalyzer: false,
81
+
+ reportTitle: "Bundle Analysis",
82
+
+ fileName: "bundle-report.html",
83
+
+ }),
84
+
],
85
+
```
86
+
87
+
> ℹ️ These settings will make analyzer work in static mode instead of server mode. This way, an `html` document is generated with the desired name, we can open it manually, but no server is created.
0 commit comments