need your help for hot-reloading server with webpack
See original GitHub issueHi everyone!
After reading the article Hot reload all the things! I’ve created a simple koa-hot-reloading-server.
Unfortunately it doesn’t work while changes are recompile. original server based on express works fine express-hot-reloading-server
the main thing is in this code:
import http from 'http'
import app from './server'
const server = http.createServer(app)
let currentApp = app
server.listen(3000)
if (module.hot) {
module.hot.accept('./server', () => {
server.removeListener('request', currentApp)
server.on('request', app)
currentApp = app
})
}
I’ve translated it into koa:
import http from 'http';
import app from './server';
const port = 3000;
const appCallback = app.callback();
const server = http.createServer(appCallback);
let currentApp = appCallback;
server.listen(port);
if (module.hot) {
module.hot.accept('./server', () => {
server.removeListener('request', currentApp);
server.on('request', appCallback);
currentApp = appCallback;
});
}
console.log(`Server running on: http://localhost: ${port}`);
it serves requests but doesnt reload servers new code, e.g. these lines are not have an action
server.removeListener('request', currentApp);
server.on('request', appCallback);
currentApp = appCallback;
Help me please
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Hot Module Replacement - webpack
Hot Module Replacement (or HMR) is one of the most useful features offered by webpack. It allows all kinds of modules to be...
Read more >How to have hot reload when using "webpack serve" on ...
Basically, are you booting your localhost by running a script (e.g: node fileName.js ), or are you using your CLI to run a...
Read more >How to hot-reload with Webpack? - codegodzilla.com - Medium
Prerequisites: Make sure you understand the basics of how to use TypeScript with Webpack. For that You can read my last lesson, here....
Read more >Solution for Webpack 5 Dev Server Not Live Reloading
There is currently a bug with Webpack 5 and webpack -dev- server not working that is caused by the existence of a browserslist...
Read more >10 - webpack dev server - serve content and hot reload it
Your browser can't play this video. Learn more. Switch camera.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You need to call
app.callback()
uponmodule.hot.accept
. A difference between Koa and Express is thatexpress
“instances” are actually functions (which can be passed tohttp.createServer
directly) with extra properties on them, whereasnew Koa()
returns an object, with a method (calledcallback
) which returns a function for use withhttp.createServer
.This should work:
@jonathanong does node-dev works well with babel 7?