From 1bd43d58f9a36dc581d8e93736f8b30378d89abe Mon Sep 17 00:00:00 2001 From: SuperOleg39 Date: Fri, 22 Dec 2023 19:15:25 +0200 Subject: [PATCH] feat: added option to exclude cached from stats (#441) --- middleware.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/middleware.js b/middleware.js index 086a24c..5b9d1fc 100644 --- a/middleware.js +++ b/middleware.js @@ -9,6 +9,8 @@ function webpackHotMiddleware(compiler, opts) { typeof opts.log == 'undefined' ? console.log.bind(console) : opts.log; opts.path = opts.path || '/__webpack_hmr'; opts.heartbeat = opts.heartbeat || 10 * 1000; + opts.statsCached = + typeof opts.statsCached == 'undefined' ? true : opts.statsCached; var eventStream = createEventStream(opts.heartbeat); var latestStats = null; @@ -31,7 +33,7 @@ function webpackHotMiddleware(compiler, opts) { if (closed) return; // Keep hold of latest stats so they can be propagated to new clients latestStats = statsResult; - publishStats('built', latestStats, eventStream, opts.log); + publishStats('built', latestStats, eventStream, opts.log, opts.statsCached); } var middleware = function (req, res, next) { if (closed) return next(); @@ -40,7 +42,7 @@ function webpackHotMiddleware(compiler, opts) { if (latestStats) { // Explicitly not passing in `log` fn as we don't want to log again on // the server - publishStats('sync', latestStats, eventStream); + publishStats('sync', latestStats, eventStream, false, opts.statsCached); } }; middleware.publish = function (payload) { @@ -114,10 +116,10 @@ function createEventStream(heartbeat) { }; } -function publishStats(action, statsResult, eventStream, log) { +function publishStats(action, statsResult, eventStream, log, statsCached) { var statsOptions = { all: false, - cached: true, + cached: statsCached, children: true, modules: true, timings: true,