Skip to content

Commit 3482601

Browse files
committed
feat(plugin): introduce plugin option to pass onto compilation.getStats().toJson()
Signed-off-by: hainenber <[email protected]>
1 parent b4e1c54 commit 3482601

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ const Visualizer = require('webpack-visualizer-plugin2');
1919

2020
module.exports = {
2121
plugins: [
22-
new Visualizer({
22+
new Visualizer(
23+
{
2324
filename: path.join('..', 'stats', 'statistics.html'),
2425
throwOnError: true,
26+
},
27+
{
2528
chunkModules: true
2629
}),
2730
],

src/plugin/plugin.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@ let cssString = fs.readFileSync(path.join(__dirname, './style.css'), 'utf8');
66
let jsString = fs.readFileSync(path.join(__dirname, './main.js'), 'utf8');
77

88
module.exports = class VisualizerPlugin {
9-
constructor(opts = {}) {
9+
constructor(opts = {}, statOpts = {}) {
1010
this.opts = {
1111
filename: 'stats.html',
1212
throwOnError: true,
13-
chunkModules: true,
1413
...opts,
1514
};
15+
this.statOpts = {
16+
chunkModules: true,
17+
...statOpts,
18+
};
1619
}
1720

1821
apply(compiler) {
1922
compiler.hooks.emit.tapAsync('Visualizer', (compilation, callback) => {
2023
let html;
2124

2225
try {
23-
let stats = compilation.getStats().toJson({ chunkModules: this.opts.chunkModules });
26+
let stats = compilation.getStats().toJson({ chunkModules: this.statOpts.chunkModules });
2427
let stringifiedStats = JSON.stringify(stats).replace(/</g, '&lt;').replace(/>/g, '&gt;');
2528

2629
html = `

0 commit comments

Comments
 (0)