webpack: Enabling the experimental option experiments.buildHttp will cause HMR to not work.

Bug report

What is the current behavior? Enabling the experimental option experiments.buildHttp will cause HMR to not work.

If the current behavior is a bug, please provide the steps to reproduce. 1、I’ve provided a small library of examples to reproduce the problem: https://github.com/LP1994/experiments_buildHttp_hmr.git 2、After downloading the project, go to the project root directory and execute the commands in the following order: 1)npm --force install 2)npm run dev

What is the expected behavior? Enable experimental option experiments.buildHttp. HMR also works fine.

Other relevant information: webpack version:
webpack 5.74.0

Node.js version: node 18.6.0

Operating System: Windows 11 Professional Edition 21H2 22000.832

Additional tools: npm 8.15.1

My demo library: https://github.com/LP1994/experiments_buildHttp_hmr.git

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 24 (9 by maintainers)

Most upvoted comments

@alexander-akait Thanks again for your prompt reply.

Just to initialize the dependencies needed in the project for those who don’t have the corresponding npm package installed.

Use npm i for this, not webpack init

@LP1994 Your should not change it in webpack, change it to true https://github.com/webpack/webpack-dev-server/blob/master/lib/Server.js#L478, also remove watchFiles (from dev server, it is only for resources which are not in bundle, for example - change PHP files)

Because webpack change compiler.options.externalsPresets (https://github.com/webpack/webpack-dev-server/blob/master/lib/Server.js#L464), we should provide ability to undestand we are in browser env or not…

@vankop Bug here https://github.com/webpack/webpack/blob/main/lib/config/defaults.js#L1019, buildHttp disable web target, so webpack-dev-server is assuming we are not in web enviroment and avoding include client code for hot reloading