react hmr example
dKab opened this issue · 13 comments
I'd love to see working example of koa-webpack with webpack 2 and react-hot-loader3
@cmoad I managed to get it working in my setup. You may take a look at it here: https://github.com/dKab/recipy-book
@dKab wonderful! could I link to your project in koa-webpack's README?
@shellscape sure, no problem. Thanks for the package by the way.
Perhaps I'm misunderstanding, but I don't see that you are hot reloading the server code. I'm trying to setup a project with only server code (no react). I also see in your readme:
Hot reloading is enabled. Client bundle will be recompiled with every change, however server bundle won't (HMR wouldn't work if server was recompiled on every change).
but I don't see that you are hot reloading the server code
Oops. Sorry. I din't know hmr can can be applied to server code as well as to client.
Perhaps it can't and that's why I am struggling.
But I don't I think I grasp the concept of hmr on the server. On the client it's pretty clear - bundle is updated on the fly and thus you don't have to reload the browser to see changes. On the other hand what would be the idea of hmr on the server side? I mean why the solution when you track changes in source files and recompile server bundle and restart node with new bundle wouldn't work for you?
To achieve this you could (assuming you use webpack for budling server code) start webpack in watch mode and use something like nodemon to restart your server script when bundle is changed.
Or am I missing something?
From webpack-hot-middleware's readme:
This module is only concerned with the mechanisms to connect a browser client to a webpack server & receive updates. It will subscribe to changes from the server and execute those changes using webpack's HMR api.
That links to the HMR API which to me reads that it's only concerned with client-side things, as that's webpack's targeted focus.
The suggestion by @dKab sounds like a winner. But server-side module reloading may be out of scope for this module, given the client-side focus. It sounds like something that needs to work externally in conjunction with koa-webpack.
Note: the linked example abandoned koa-webpack, claiming it was broken: dKab/recipe-book@701deac
@bryanlarsen that's humorous, but thank you for sharing for the benefit of others. closing this issue as it's pretty stale. we'll welcome contributed examples for different platforms (like React) but it's not something that's a priority at the moment.
Was anyone able to reproduce a public working example with react?
I have React hot loading working with "koa-webpack": "^1.0.0"
. "koa-webpack": "^2.0.3",
seems to break it and I haven't found the missing link yet. Probably I'll go back to using v1.