th0r / webpack-bundle-analyzer
- среда, 2 ноября 2016 г. в 03:13:02
JavaScript
Webpack plugin and CLI utility that represents bundle content as convenient interactive zoomable treemap
Webpack plugin and CLI utility that represents bundle content as convenient interactive zoomable treemap
Just take a look at this demo:
This module will help you:
And the best thing is it supports minified bundles! It parses them to get real size of bundled modules.
There are two ways to use this module:
npm install --save-dev webpack-bundle-analyzer
In webpack.config.js
:
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
// ...
plugins: [new BundleAnalyzerPlugin()]
// ...
BundleAnalyzerPlugin
constructor can take an optional configuration object that defaults to this:
new BundleAnalyzerPlugin({
// Start analyzer HTTP-server.
// You can use this plugin to just generate Webpack Stats JSON file by setting `startAnalyzer` to `false`
// and `generateStatsFile` to `true`.
startAnalyzer: true,
// Analyzer HTTP-server port
analyzerPort: 8888,
// Automatically open analyzer page in default browser if `startAnalyzer` is `true`
openAnalyzer: true,
// If `true`, Webpack Stats JSON file will be generated in bundles output directory
generateStatsFile: false,
// Name of Webpack Stats JSON file that will be generated if `generateStatsFile` is `true`.
// Relative to bundles output directory.
statsFilename: 'stats.json',
})
You can also analyze already existing bundles if you have Webpack Stats JSON file.
You can generate it using BundleAnalyzerPlugin
with generateStatsFile
option set to true
or with this simple
command: webpack --profile --json > stats.json
webpack-bundle-analyzer --help
will show you all usage information.