Skip to content

Commit

Permalink
create bundle size analysis on build
Browse files Browse the repository at this point in the history
I think there is room for improvements in distribution bundle size,
as zxing is currently distributed directly here as UMD.
We could possible be in better situation if we could use @zxing/library
 which is released as ESM modules nowadays.

As a helper for that possible endeavour this [webpack-bundle-analyzer](https://www.npmjs.com/package/webpack-bundle-analyzer)
 plugin creates a static HTML page to dist/report.html during build.
  • Loading branch information
Snurppa committed Aug 11, 2023
1 parent 8436a42 commit 1a54acc
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 3 deletions.
193 changes: 193 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"typescript": "^4.3.2",
"typings": "^2.1.1",
"webpack": "^5.37.0",
"webpack-bundle-analyzer": "^4.9.0",
"webpack-cli": "^4.7.0"
},
"remarkConfig": {
Expand Down
13 changes: 10 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const path = require("path");
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;


module.exports = {
// bundling mode
Expand All @@ -7,13 +9,13 @@ module.exports = {
entry: "./src/index.ts",
// output bundles (location)
output: {
path: path.resolve( __dirname, "dist" ),
path: path.resolve(__dirname, "dist"),
filename: "html5-qrcode.min.js",
library: "__Html5QrcodeLibrary__",
},
// file resolutions
resolve: {
extensions: [ ".ts", ".js" ],
extensions: [".ts", ".js"],
},
target: "web",
module: {
Expand All @@ -28,5 +30,10 @@ module.exports = {
optimization: {
minimize: true,
usedExports: true
}
},
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: "static"
})
]
};

0 comments on commit 1a54acc

Please sign in to comment.