webpack-chunk-metadata-plugin
A Webpack plugin to generate and embed chunk-level metadata for advanced bundle analysis, runtime inspection, and custom tooling.
Features
- Infers the type of chunk
- Supports treeshaken exports
- Supports gzip size calculation for each module
- Helps in bundle visualization and performance optimization
Installation
npm install --save-dev webpack-chunk-metadata-plugin
OR
yarn add --dev webpack-chunk-metadata-plugin
Usage
In your Webpack configuration:
// webpack.config.js or webpack.config.ts
const { withChunkMetadataPlugin } = require("webpack-chunk-metadata-plugin");
// Assuming config is earlier webpack config.
const webpackConfig = withChunkMetadataPlugin({ enabled: true })(config);
Example Output
The plugin will generate a file like client.json
in your Webpack output directory:
{
"main": {
"id": "main",
"parsedSize": 1300,
"gzipSize": 643,
"statSize": 1549,
"type": "sync",
"modules": [
{
"label": "./src/index.js",
"path": "./src/index.js",
"exports": ["default", "foo"],
"treeshakenExports": ["foo"],
"parsedSize": 1200,
"gzipSize": 456,
"statSize": 1249
}
]
}
}
Development
git clone https://github.com/shantanu2307/webpack-chunk-metadata-plugin.git
cd webpack-chunk-metadata-plugin
npm install
npm run build
To test locally in a Webpack project, use npm link
:
cd webpack-chunk-metadata-plugin
npm link
cd ../your-webpack-project
npm link webpack-chunk-metadata-plugin
License
MIT © Shantanu Goyal