vite-bundle-explorer 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  Bundle analyzer and visualizer tool for vite.
4
4
 
5
5
  Current features:
6
+
6
7
  - Chunk size treemap
7
8
  - Module import graph
8
9
  - Build stats report
@@ -47,3 +48,24 @@ Once your build is complete and `stats.json` is generated, you can launch the we
47
48
  ```shell
48
49
  npx vite-bundle-explorer ./dist/stats.json
49
50
  ```
51
+
52
+ ## Options
53
+
54
+ You can pass options to stats plugin
55
+
56
+ ```javascript
57
+ export default defineConfig({
58
+ plugins: [
59
+ statsPlugin({
60
+ // ...options
61
+ })
62
+ ]
63
+ });
64
+ ```
65
+
66
+ | Parameter | Type | Default | Description |
67
+ |------------------------|-----------|--------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------|
68
+ | `reportCompressedSize` | `boolean` | Same as Vite's [build.reportCompressedSize](https://vite.dev/config/build-options.html#build-reportcompressedsize) | Calculate compressed size of chunks. Might affect performance. |
69
+ | `reportDirectoryName` | `string` | `"bundle-report"` | Name of the output directory |
70
+ | `emitHtml` | `boolean` | `true` | Generate interactive HTML report |
71
+ | `emitJson` | `boolean` | `false` | Generate `stats.json` file |
package/bin/index.js CHANGED
@@ -3,9 +3,6 @@ import { createServer } from 'node:http';
3
3
  import fs from 'node:fs/promises';
4
4
  import path from 'node:path';
5
5
 
6
- const statsFile = path.resolve(process.cwd(), process.argv[2] ?? 'dist/stats.json');
7
- const stats = await fs.readFile(statsFile, { encoding: 'utf-8' });
8
-
9
6
  const mimeTypes = {
10
7
  '.js': 'text/javascript',
11
8
  '.html': 'text/html',
@@ -16,17 +13,18 @@ const mimeTypes = {
16
13
  const server = createServer((req, res) => {
17
14
  const { url } = req;
18
15
 
19
- if (url === '/stats.json') {
20
- res.writeHead(200, { 'Content-Type': 'application/json' });
21
- return res.end(stats);
22
- }
23
-
24
- const file = path.join(import.meta.dirname, '..', 'dist', url.slice(1) || 'index.html');
25
- fs.readFile(file).then((buffer) => {
26
- const extension = path.extname(file);
27
- res.writeHead(200, { 'content-type': mimeTypes[extension] });
28
- return res.end(buffer);
29
- });
16
+ const root = process.argv[2];
17
+ const file = path.join(root, url.slice(1) || 'index.html');
18
+ fs.readFile(file)
19
+ .then((buffer) => {
20
+ const extension = path.extname(file);
21
+ res.writeHead(200, { 'content-type': mimeTypes[extension] });
22
+ return res.end(buffer);
23
+ })
24
+ .catch(() => {
25
+ res.writeHead(404, { 'content-type': 'text/plain' });
26
+ return res.end('Not found');
27
+ });
30
28
  });
31
29
  server.listen(3322);
32
30
  console.log('Listening on http://localhost:3322');