Skip to content

Commit

Permalink
chore: add webpack bundle analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 27, 2024
1 parent 0514a74 commit a05dcdc
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 30 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"vite": "^5.3.1",
"vitest": "^1.6.0",
"webpack": "^5.92.1",
"webpack-bundle-analyzer": "^4.10.2",
"webpack-cli": "^5.1.4"
},
"packageManager": "pnpm@9.4.0"
Expand Down
123 changes: 111 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 9 additions & 18 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require("node:path");
const fsp = require("node:fs/promises");

Check warning on line 2 in webpack.config.js

View workflow job for this annotation

GitHub Actions / autofix

'fsp' is assigned a value but never used. Allowed unused vars must match /^_/u

Check warning on line 2 in webpack.config.js

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest, 20)

'fsp' is assigned a value but never used. Allowed unused vars must match /^_/u

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

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

Expand Down Expand Up @@ -29,17 +30,7 @@ module.exports = {
},
},
plugins: [
// https://github.com/unjs/jiti/issues/109
// TODO: Remove in next semver-major version
(compiler) => {
const plugin = { name: "replace node: protocol" };
compiler.hooks.done.tap(plugin, async () => {
const jitiDist = path.resolve(compiler.options.context, "dist/jiti.js");
const src = await fsp.readFile(jitiDist, "utf8");
const newSrc = src.replace(/require\("node:/g, 'require("');
await fsp.writeFile(jitiDist, newSrc, "utf8");
});
},
process.argv.find(arg => arg.includes('--analyze')) && new BundleAnalyzerPlugin({})
],
ignoreWarnings: [/critical dependency:/i],
module: {
Expand All @@ -58,13 +49,13 @@ module.exports = {
chunkIds: "named",
minimizer: isProd
? [
new TerserPlugin({
terserOptions: {
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
mangle: false,
},
}),
]
new TerserPlugin({
terserOptions: {
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
mangle: false,
},
}),
]
: [],
},
};

0 comments on commit a05dcdc

Please sign in to comment.