From c41a47cf8e8a2733d7087725bdf537b56b7044a1 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Tue, 8 Dec 2020 14:36:46 +0300 Subject: [PATCH] fix: empty entries --- lib/utils/DevServerPlugin.js | 44 +++++++++++++++++++----------------- lib/utils/updateCompiler.js | 1 + 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/lib/utils/DevServerPlugin.js b/lib/utils/DevServerPlugin.js index 312e3a449e..406c168b8a 100644 --- a/lib/utils/DevServerPlugin.js +++ b/lib/utils/DevServerPlugin.js @@ -37,6 +37,7 @@ class DevServerPlugin { : ''; /** @type {string} */ let path = ''; + // only add the path if it is not default if ( options.client && @@ -45,11 +46,13 @@ class DevServerPlugin { ) { path = `&path=${options.client.path}`; } + /** @type {string} */ const port = options.client && options.client.port ? `&port=${options.client.port}` : ''; + /** @type {string} */ const clientEntry = `${require.resolve( '../../client/default/' @@ -119,14 +122,22 @@ class DevServerPlugin { */ // eslint-disable-next-line no-shadow const checkInject = (option, _config, defaultValue) => { - if (typeof option === 'boolean') return option; - if (typeof option === 'function') return option(_config); + if (typeof option === 'boolean') { + return option; + } + + if (typeof option === 'function') { + return option(_config); + } + return defaultValue; }; const compilerOptions = compiler.options; + compilerOptions.plugins = compilerOptions.plugins || []; - /** @type {Boolean} */ + + /** @type {boolean} */ const isWebTarget = compilerOptions.externalsPresets ? compilerOptions.externalsPresets.web : [ @@ -138,6 +149,7 @@ class DevServerPlugin { undefined, null, ].includes(compilerOptions.target); + /** @type {Entry} */ const additionalEntries = checkInject( options.injectClient, @@ -153,24 +165,12 @@ class DevServerPlugin { // use a hook to add entries if available if (EntryPlugin) { - compiler.hooks.make.tapPromise('DevServerPlugin', (compilation) => - Promise.all( - additionalEntries.map( - (entry) => - new Promise((resolve, reject) => { - compilation.addEntry( - compiler.context, - EntryPlugin.createDependency(entry, {}), - {}, // global entry - (err) => { - if (err) return reject(err); - resolve(); - } - ); - }) - ) - ) - ); + for (const additionalEntry of additionalEntries) { + new EntryPlugin(compiler.context, additionalEntry, { + // eslint-disable-next-line no-undefined + name: undefined, + }).apply(compiler); + } } else { compilerOptions.entry = prependEntry( compilerOptions.entry || './src', @@ -185,6 +185,7 @@ class DevServerPlugin { const providePlugin = new webpack.ProvidePlugin({ __webpack_dev_server_client__: getSocketClientPath(options), }); + providePlugin.apply(compiler); if ( @@ -195,6 +196,7 @@ class DevServerPlugin { ) { // apply the HMR plugin, if it didn't exist before. const plugin = new webpack.HotModuleReplacementPlugin(); + plugin.apply(compiler); } } diff --git a/lib/utils/updateCompiler.js b/lib/utils/updateCompiler.js index a2b4e8f712..db77355950 100644 --- a/lib/utils/updateCompiler.js +++ b/lib/utils/updateCompiler.js @@ -4,6 +4,7 @@ const DevServerPlugin = require('./DevServerPlugin'); function updateCompiler(compiler, options) { const compilers = compiler.compilers || [compiler]; + // eslint-disable-next-line no-shadow compilers.forEach((compiler) => { new DevServerPlugin(options).apply(compiler);