ericclemmons/start-server-webpack-plugin

Restart on every rebuild

antonyisoardi opened this issue · 10 comments

Not so sure if anyone else has experienced this, BUT!... I've noticed that the server is only being restarted on every second rebuild.

Rebuilds are successful every time, however in order for me to get the server restarted I have to make a second change.

I'm on 2.2.5

I'm not seeing it under version?

As a separate confirmation, our team is seeing this problem more-or-less as a matter of course with 2.2.5 running under macOS. I'll try the beta and see how that goes.

Some quick debugging suggests that this function is wrong:

afterEmit(compilation, callback) {
    if (this.worker && this.worker.isConnected()) {
      const signal = this._getSignal();
      if (signal) {
        process.kill(this.worker.process.pid, signal);
      }
      return callback();
    }

    this.startServer(compilation, callback);
  }

On the first pass, the code finds the connected worker, kills the server, and then returns the callback. The server is now dead (killed), but not restarted. On the second save, the if() clause doesn't trigger, so the server is started.

Note that this only happens when signal is set. It's possible there's a configuration issue here on my part (I don't think HMR is working properly in our configuration), but in general, my first thought is if start-server-webpack stops the server after a build, it should restart it again.

Quick follow-up: our HMR was configured in poll mode, but start-server-webpack-plugin was configured with signal: true. When I use match 'signal: falsewithwebpack/hot/poll?500orsignal: truewithwebpack/hot/signal`, everything starts working.

Upon careful reading of the start-server-webpack-plugin, I think the documentation technically says this, but HMR hard enough for us to get configured (and not completely working until now) that I wonder if:

  • The documentation could be a little clearer about how important matching settings is?
  • If there's a way in code to catch the misconfiguration?

(One of the other tell-tales of our misconfiguration is that rs would sometimes exception out, because the kill command assumes the worker is still connected, but since the web server would stop every other build, sometimes the server wouldn't be working and the rs command would generate an exception.)

@antonyisoardi -- any chance the same issue for you?

Short version: I think this plugin works correctly as long as the configuration exactly matches the HMR configuration. However, if there is a mismatch, there are some subtle bugs where it would be nice if there was catastrophic failure.

For my setup, signal: true with webpack/hot/signal didn't work for me.

But, signal: false with webpack/hot/poll worked for me.

Hey, so is there any way to enable restart on rebuild without HMR?

@AlexMost super late response, but I am using the @beta version without any hmr and getting a proper restart after each build