ericclemmons / start-server-webpack-plugin

Automatically start your server once Webpack's build completes.
MIT License
158 stars 26 forks source link

Restart on every rebuild #30

Open antonyisoardi opened 6 years ago

antonyisoardi commented 6 years ago

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.

wmertens commented 6 years ago

are you using the @beta versionz/

antonyisoardi commented 6 years ago

I'm on 2.2.5

wmertens commented 6 years ago

Ok, try the @beta version

Wout.

On Thu, Oct 4, 2018 at 3:15 PM Antony notifications@github.com wrote:

I'm on 2.2.5

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ericclemmons/start-server-webpack-plugin/issues/30#issuecomment-427013985, or mute the thread https://github.com/notifications/unsubscribe-auth/AADWloKK1XFCEdh9FqiQghKy6n4K50Jzks5uhgndgaJpZM4XHq_C .

antonyisoardi commented 6 years ago

I'm not seeing it under version?

rayalan commented 6 years ago

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.

rayalan commented 6 years ago

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.

rayalan commented 6 years ago

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:

(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.

atifsyedali commented 4 years ago

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

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

AlexMost commented 4 years ago

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

tcosentino commented 4 years ago

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