question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can I get a simple, up-to-date and working example for hot-reloading?

See original GitHub issue
  • Node Version: v11.10.0
  • NPM Version: 6.7.0
  • koa Version: 2.7.0
  • koa-wepback Version: 5.2.1

I think the README.md should have a clear example on how to make a simple app work with hot-reloading. I’ve been trying to make this repo work for a couple days now and I can’t get any changes inside my server’s code to refresh my page.

router.get('/', (ctx, next) => {
    ctx.body = "Doesn't change unless a force a refresh manually";
});

I’ve looked at multiple examples in this GitHub issues and they’re all old and out-dated. Now the middleware uses Async/Await and it’s really unclear where to use it (before or after initialising route). It’s also unclear what should exactly be in my webpack.config for hot-reloading and if I still have the need to do this in my index file.

if (module.hot) {
    {...}
}

This is not a request for support, it’s an actual issue that there’s so little practical documentation on how to make it work correctly, a simple example would go a long way.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

13reactions
jdrydncommented, Mar 15, 2019

If async/awaitwere not core to Koa v2, you would have a valid point

Apologies šŸ™ That’s not the point I’m making. I adore Koa due to it’s core support for async/await, however this support is in the middleware functions themselves, i.e. once you enter the context scope with app.use(...). (AFAIK) Node itself doesn’t particularly support a random await in the middle of synchronous code - it has to be inside an async function.

Quoting your README directly:

const Koa = require('koa');
const koaWebpack = require('koa-webpack');

const app = new Koa();
const options = { .. };
const middleware = await koaWebpack(options);

app.use(middleware);

Should it not be:

const Koa = require('koa');
const koaWebpack = require('koa-webpack');

async bootstrap() {
  const app = new Koa();
  const options = { .. };
  const middleware = await koaWebpack(options);

  app.use(middleware);
  return app;
}

bootstrap()
  .then(app => app.listen(8080))
  .catch(err => console.error(err));

In order to support this await keyword?

… And to bring this issue full-circle, a working example file included in this repo would have cleared this up!

5reactions
corysimmonscommented, Oct 6, 2019

Why do you hate providing examples? It’s the easiest way for someone to learn/use your project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set up React Hot Loader in 10 minutes - LogRocket Blog
This is called hot reloading. It works by replacing a module of the application during runtime with an updated one so that it's...
Read more >
Hot Module Replacement in Redux - Toptal
This is a minimal example of hot module replacement (or HMR) in a Redux application. The working demo code is hosted on GitHub....
Read more >
Difference between Hot Reloading and Live ... - GeeksforGeeks
Hot reloading and Live reloading are something that Reacts Native developers use on regular basis. Both have their own advantages andĀ ...
Read more >
Introducing the .NET Hot Reload experience for editing code ...
Introducing the new .NET Hot Reload user experience for editing managed code at runtime, now available through the Visual Studio 2019Ā ...
Read more >
Hot Reload - Garden
Since hot reloading is triggered via Garden's file system watcher, hot reloading only occurs while a watch-mode Garden command is running. Basic example....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found