-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Dynamic entries do not seem to be well supported by webpack-dev-server.
The DynamicEntryPlugin is a poorly documented webpack feature, but the webpack entry option can be defined as a function that returns either an entry object or one that returns a Promise which resolves to an object.
e.g.
// webpack.config.js
export default {
entry: async () => {
const entries = {};
// generate entries
return entries;
}
//...
}This was sort of addressed with #801 and #802 in which the following lines were added in /lib/util/addDevServerEntrypoints.js:
if (typeof wpOpt.entry === 'function') {
wpOpt.entry = wpOpt.entry(devClient);
}However this is incorrect for several reasons:
-
For one, the
entryfunction is not expected to accept any arguments, so passingdevClientinto the function is a bit confusing. This won't necessarily add thedevClientto the resulting entry object unless it was defined by the user in such a way that it uses that argument. Why not append it to the finalentryobject yourself so you can be sure it is included? -
This also redefines the
wpOpt.entryas a static object by running the function, rather than keeping it dynamic by, say, wrapping the function in another closure that can re-run and re-appenddevClienteach time it is invoked. -
Async functions are completely broken. Since this code resolves the function, an async
wpOpt.entryfunction would resolve to aPromiseobject and webpack will throw an error because it does not expect this.
I'd be happy to open a PR to fix this if it would be accepted.