Skip to content

Commit

Permalink
fix: empty entries
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Dec 8, 2020
1 parent 2a50946 commit 1d8456f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
44 changes: 23 additions & 21 deletions lib/utils/DevServerPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DevServerPlugin {
: '';
/** @type {string} */
let path = '';

// only add the path if it is not default
if (
options.client &&
Expand All @@ -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/'
Expand Down Expand Up @@ -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
: [
Expand All @@ -138,6 +149,7 @@ class DevServerPlugin {
undefined,
null,
].includes(compilerOptions.target);

/** @type {Entry} */
const additionalEntries = checkInject(
options.injectClient,
Expand All @@ -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',
Expand All @@ -185,6 +185,7 @@ class DevServerPlugin {
const providePlugin = new webpack.ProvidePlugin({
__webpack_dev_server_client__: getSocketClientPath(options),
});

providePlugin.apply(compiler);

if (
Expand All @@ -195,6 +196,7 @@ class DevServerPlugin {
) {
// apply the HMR plugin, if it didn't exist before.
const plugin = new webpack.HotModuleReplacementPlugin();

plugin.apply(compiler);
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/utils/updateCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1d8456f

Please sign in to comment.