From 04f3914390a2cae7c9f1788c85b2ea5cd6f37630 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Wed, 25 Aug 2021 17:30:03 +0530 Subject: [PATCH] fix: show warning when `hot` is enabled with HMR plugin in config --- lib/Server.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index 898646266a..0968f4cebb 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -1044,16 +1044,20 @@ class Server { // TODO remove after drop webpack v4 support compiler.options.plugins = compiler.options.plugins || []; - if ( - this.options.hot && - !compiler.options.plugins.find( + if (this.options.hot) { + const HMRPluginExists = compiler.options.plugins.find( (p) => p.constructor === webpack.HotModuleReplacementPlugin - ) - ) { - // apply the HMR plugin, if it didn't exist before. - const plugin = new webpack.HotModuleReplacementPlugin(); + ); - plugin.apply(compiler); + if (HMRPluginExists) { + this.logger.warn( + `"hot: true" automatically applies HMR plugin, you don't have to add it manually to your webpack configuration.` + ); + } else { + // apply the HMR plugin + const plugin = new webpack.HotModuleReplacementPlugin(); + plugin.apply(compiler); + } } });