From b4e1c54a073edafd8986ef2380d4104a1502a59c Mon Sep 17 00:00:00 2001 From: hainenber Date: Wed, 22 Jan 2025 22:03:12 +0700 Subject: [PATCH 1/2] feat(plugin): introduce plugin option `chunkModules` Signed-off-by: hainenber --- README.md | 3 ++- src/plugin/plugin.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e4e18d0..159e4d5 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ module.exports = { plugins: [ new Visualizer({ filename: path.join('..', 'stats', 'statistics.html'), - throwOnError: true + throwOnError: true, + chunkModules: true }), ], } diff --git a/src/plugin/plugin.js b/src/plugin/plugin.js index f061652..0463db5 100644 --- a/src/plugin/plugin.js +++ b/src/plugin/plugin.js @@ -10,6 +10,7 @@ module.exports = class VisualizerPlugin { this.opts = { filename: 'stats.html', throwOnError: true, + chunkModules: true, ...opts, }; } @@ -19,7 +20,7 @@ module.exports = class VisualizerPlugin { let html; try { - let stats = compilation.getStats().toJson({ chunkModules: true }); + let stats = compilation.getStats().toJson({ chunkModules: this.opts.chunkModules }); let stringifiedStats = JSON.stringify(stats).replace(//g, '>'); html = ` From 34e90f92b53383aab716a5241c534dee835aeee7 Mon Sep 17 00:00:00 2001 From: hainenber Date: Wed, 22 Jan 2025 22:15:21 +0700 Subject: [PATCH 2/2] feat(plugin): introduce plugin option to pass onto `compilation.getStats().toJson()` Signed-off-by: hainenber --- README.md | 5 ++++- src/plugin/plugin.js | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 159e4d5..4f81079 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,12 @@ const Visualizer = require('webpack-visualizer-plugin2'); module.exports = { plugins: [ - new Visualizer({ + new Visualizer( + { filename: path.join('..', 'stats', 'statistics.html'), throwOnError: true, + }, + { chunkModules: true }), ], diff --git a/src/plugin/plugin.js b/src/plugin/plugin.js index 0463db5..4abe674 100644 --- a/src/plugin/plugin.js +++ b/src/plugin/plugin.js @@ -6,13 +6,16 @@ let cssString = fs.readFileSync(path.join(__dirname, './style.css'), 'utf8'); let jsString = fs.readFileSync(path.join(__dirname, './main.js'), 'utf8'); module.exports = class VisualizerPlugin { - constructor(opts = {}) { + constructor(opts = {}, statOpts = {}) { this.opts = { filename: 'stats.html', throwOnError: true, - chunkModules: true, ...opts, }; + this.statOpts = { + chunkModules: true, + ...statOpts, + }; } apply(compiler) { @@ -20,7 +23,7 @@ module.exports = class VisualizerPlugin { let html; try { - let stats = compilation.getStats().toJson({ chunkModules: this.opts.chunkModules }); + let stats = compilation.getStats().toJson(this.statOpts); let stringifiedStats = JSON.stringify(stats).replace(//g, '>'); html = `