-
-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HMR example #39
HMR example #39
Conversation
@@ -0,0 +1,15 @@ | |||
{ | |||
"name": "backpack-examples-basic", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should rename to backpack-examples-hmr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, just fixed with backpack-example-hot-module-replacement
.
I can rename the whole thing to HMR, which is soooo much shorter!
@jaredpalmer Check out the demo in the comments above. It's typical of how we work on our projects (yay to not breaking socket connections & polling issues between restarts!), which works well, especially if you have |
If I were to make a hit list for this to reach parity with
|
Thinking on this more, would it be OK for users to not have to worry about writing app.listen(port, (err) => {
if (err) {
console.error(err)
}
if (__DEV__) { // webpack flags!
console.log('> in development')
}
console.log(`> listening on port ${port}`)
}) It's sooo nice just writing: import express from "express";
export default express().get("/", async (req, res) => {
try {
const thing = await Promise.resolve({ one: 'two' }) // async/await!
return res.json({...thing, hello: 'world'}) // object-rest-spread!
} catch (e) {
return res.json({ error: e.message })
}
}); |
this is awesome. we definitely need to think through |
@jaredpalmer One of the techniques I've used in the past was checking the following:
|
@jaredpalmer For a separate issue, it would be good to have a contrived example of usage as a CLI tool or non-web stuff. I personally didn't consider it, but it makes sense! |
@ericclemmons do you think we need to document how HMR works (or doesn't work) with packages or services that do clustering such as |
Thanks for the tip on throng, I've never heard of it! So, the dilemma with HMR is that if you make changes in the same file that has Which is why these last few commits abstracted away the "server". There are a couple ways we can tackle this:
|
Hi guys, I just wonder what happened with this functionality. I love using Backpack, but I came to the point where I need to connect to a Kafka cluster only once and not on every file save and it is impossible to achieve right now, isn't it? |
@mxstbr may have some insights. Backpack doesn't actually use HMR. It does a full restart managed by chokidar. However, we can easily add that functionality if ppl want it (my Razzle project does it). |
I use Razzle for SSR client app, but this one is only a Node.js API and HMR would be great in order to achieve sigle connections to databases or straming platforms. |
@mxstbr @jaredpalmer I think adding that functionality would not hurt anyone and would be only a benefit, what do you think? |
This is a demo of HMR adds a
hot-module-replacement
example, but requires some changes, as seen in my example project:app.js
(and all of its dependencies) is where all changes should be made.index.js
is largely the HMR entry-point that gets started once upon compile, but should not change at all.entry.main
could point tobackpack-core/scripts/hot.js
or similar that would handle the boilerplate? The caveat is that you don't want the module that starts the server ever changing. (Check outindex.js
to see how this works. I do believe it's solvable though.)start-server-webpack-plugin
(meant for HMR, that's akin toreload-server-webpack-plugin
), but it's simple enough to be within thedev
script. You wouldn't neednodemon
anymore.