Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HMR/Live Reloading when running against webpack v5 and have an array of targets when using webpack-dev-server v3 #3271

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 17 additions & 8 deletions lib/utils/addEntries.js
Expand Up @@ -117,15 +117,24 @@ function addEntries(config, options, server) {

// eslint-disable-next-line no-shadow
[].concat(config).forEach((config) => {
// In webpack v5 target can be a string, an array of strings, null, or undefined
/** @type {Array<string>} */
const targets = Array.isArray(config.target)
? config.target
: [config.target];

/** @type {Boolean} */
const webTarget = [
'web',
'webworker',
'electron-renderer',
'node-webkit',
undefined, // eslint-disable-line
null,
].includes(config.target);
const webTarget = targets.some((target) => {
return [
'web',
'webworker',
'electron-renderer',
'node-webkit',
undefined, // eslint-disable-line
null,
].includes(target);
});

/** @type {Entry} */
const additionalEntries = checkInject(
options.injectClient,
Expand Down
6 changes: 4 additions & 2 deletions test/server/utils/addEntries.test.js
Expand Up @@ -307,9 +307,11 @@ describe('addEntries util', () => {
Object.assign({}, config),
Object.assign({ target: 'web' }, config),
Object.assign({ target: 'webworker' }, config),
Object.assign({ target: ['web', 'webworker'] }, config),
Object.assign({ target: ['web', 'es5'] }, config),
Object.assign({ target: 'electron-renderer' }, config),
Object.assign({ target: 'node-webkit' }, config),
Object.assign({ target: 'node' }, config) /* index:5 */,
Object.assign({ target: 'node' }, config) /* index:7 */,
];

const devServerOptions = {};
Expand All @@ -318,7 +320,7 @@ describe('addEntries util', () => {

// eslint-disable-next-line no-shadow
webpackOptions.forEach((webpackOptions, index) => {
const expectInline = index !== 5; /* all but the node target */
const expectInline = index !== 7; /* all but the node target */

expect(webpackOptions.entry.length).toEqual(expectInline ? 2 : 1);

Expand Down