Skip to content

Commit eb5e5ad

Browse files
committed
update sample
1 parent 8bd22f0 commit eb5e5ad

3 files changed

Lines changed: 38 additions & 8 deletions

File tree

03-bundling/06-vite/11-bundle-analyzer/README.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ Install [Node.js and npm](https://nodejs.org/en/) (20.19.0 || >=22.12.0) if they
3030
>
3131
> These tools are critical to manually increase application performance before we commit to production, and, therefore, they are usually applied over production bundles only.
3232
>
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.
3434
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:
3636

3737
```bash
38-
npm install rollup-plugin-visualizer --save-dev
38+
npm install vite-bundle-analyzer --save-dev
3939
```
4040

4141
- 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
4747
import checker from "vite-plugin-checker";
4848
import react from "@vitejs/plugin-react";
4949
import tailwindcss from "@tailwindcss/vite";
50-
+ import { visualizer } from "rollup-plugin-visualizer";
50+
+ import { analyzer } from "vite-bundle-analyzer";
5151

5252
export default defineConfig({
5353
plugins: [
5454
checker({ typescript: true }),
5555
tailwindcss(),
5656
react(),
57-
+ visualizer(),
57+
+ analyzer(),
5858
],
5959
});
6060
```
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.
88+
89+
- And build again:
90+
91+
```bash
92+
npm build
93+
```

03-bundling/06-vite/11-bundle-analyzer/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"@types/react": "^19.1.8",
1515
"@types/react-dom": "^19.1.6",
1616
"@vitejs/plugin-react": "^4.6.0",
17-
"rollup-plugin-visualizer": "^6.0.3",
1817
"typescript": "^5.8.3",
1918
"vite": "^7.0.4",
2019
"vite-bundle-analyzer": "^1.1.0",

03-bundling/06-vite/11-bundle-analyzer/vite.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ import checker from "vite-plugin-checker";
33
import react from "@vitejs/plugin-react";
44
import tailwindcss from "@tailwindcss/vite";
55
import { analyzer } from "vite-bundle-analyzer";
6-
import { visualizer } from "rollup-plugin-visualizer";
76

87
export default defineConfig({
98
plugins: [
109
checker({ typescript: true }),
1110
tailwindcss(),
1211
react(),
13-
visualizer({ template: "treemap" }),
1412
analyzer({ analyzerMode: "static", openAnalyzer: false }),
1513
],
1614
});

0 commit comments

Comments
 (0)