Skip to content

Dynamic entry is broken in webpack-dev-server #1318

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

Closed
mikegreiling opened this issue Feb 25, 2018 · 0 comments
Closed

Dynamic entry is broken in webpack-dev-server #1318

mikegreiling opened this issue Feb 25, 2018 · 0 comments

Comments

@mikegreiling
Copy link
Member

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:

  1. For one, the entry function is not expected to accept any arguments, so passing devClient into the function is a bit confusing. This won't necessarily add the devClient to 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 final entry object yourself so you can be sure it is included?

  2. This also redefines the wpOpt.entry as 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-append devClient each time it is invoked.

  3. Async functions are completely broken. Since this code resolves the function, an async wpOpt.entry function would resolve to a Promise object 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants