Skip to content

Commit a05dcdc

Browse files
committed
chore: add webpack bundle analyzer
1 parent 0514a74 commit a05dcdc

File tree

3 files changed

+121
-30
lines changed

3 files changed

+121
-30
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"vite": "^5.3.1",
8383
"vitest": "^1.6.0",
8484
"webpack": "^5.92.1",
85+
"webpack-bundle-analyzer": "^4.10.2",
8586
"webpack-cli": "^5.1.4"
8687
},
8788
"packageManager": "pnpm@9.4.0"

pnpm-lock.yaml

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

webpack.config.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const path = require("node:path");
22
const fsp = require("node:fs/promises");
33

44
const TerserPlugin = require("terser-webpack-plugin");
5+
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
56

67
const isProd = process.env.NODE_ENV === "production";
78

@@ -29,17 +30,7 @@ module.exports = {
2930
},
3031
},
3132
plugins: [
32-
// https://github.com/unjs/jiti/issues/109
33-
// TODO: Remove in next semver-major version
34-
(compiler) => {
35-
const plugin = { name: "replace node: protocol" };
36-
compiler.hooks.done.tap(plugin, async () => {
37-
const jitiDist = path.resolve(compiler.options.context, "dist/jiti.js");
38-
const src = await fsp.readFile(jitiDist, "utf8");
39-
const newSrc = src.replace(/require\("node:/g, 'require("');
40-
await fsp.writeFile(jitiDist, newSrc, "utf8");
41-
});
42-
},
33+
process.argv.find(arg => arg.includes('--analyze')) && new BundleAnalyzerPlugin({})
4334
],
4435
ignoreWarnings: [/critical dependency:/i],
4536
module: {
@@ -58,13 +49,13 @@ module.exports = {
5849
chunkIds: "named",
5950
minimizer: isProd
6051
? [
61-
new TerserPlugin({
62-
terserOptions: {
63-
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
64-
mangle: false,
65-
},
66-
}),
67-
]
52+
new TerserPlugin({
53+
terserOptions: {
54+
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
55+
mangle: false,
56+
},
57+
}),
58+
]
6859
: [],
6960
},
7061
};

0 commit comments

Comments
 (0)