Skip to content

Commit

Permalink
feat: added option to exclude cached from stats (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperOleg39 authored Dec 22, 2023
1 parent a1f821a commit 1bd43d5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1bd43d5

Please sign in to comment.