Skip to content

Content howto hmr #64

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

Merged
merged 7 commits into from
Aug 31, 2016
Merged

Content howto hmr #64

merged 7 commits into from
Aug 31, 2016

Conversation

jmreidy
Copy link
Contributor

@jmreidy jmreidy commented Aug 6, 2016

Add documentation for a basic How Module Replacement (HMR) setup. The example uses Babel, React, and CSS modules, and explains how to edit webpack.config, what dependencies are needed, and how to structure the source code.

jmreidy added 2 commits August 5, 2016 07:47
Add documentation for a basic HMR setup using Babel, React, and CSS modules. Explain how to edit webpack.config, what dependencies are needed, and how to structure the source code.
---
Hot Module Replacement (HMR) exchanges, adds, or removes modules while an application is running without a page reload. HMR is particularly useful in applications using a single state tree, since components are "dumb" and will reflect the latest application state, even after their source is changed and they are replaced.

Webpack's power lies in its customizablity, and there are MANY ways of configuring HMR given the needs of a partiular project. The approach described below uses Babel and React, but these tools are not necessary for HMR to work. If you'd like to see examples of other approaches, please request them or, better yet, open up a PR with an addition!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/s/partiular/particular

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add link to "open up a PR".

@tleunen
Copy link

tleunen commented Aug 8, 2016

Thanks a lot @jmreidy for the guide! It helped me a lot.

I have an issue though, when trying to execute this code:
screen shot 2016-08-07 at 10 40 07 pm
Which then executes this:
screen shot 2016-08-07 at 10 41 42 pm
And then fails on:
screen shot 2016-08-07 at 10 43 00 pm
screen shot 2016-08-07 at 10 43 13 pm

"babel": "^6.5.2",
"babel-core": "^6.11.4",
"babel-loader": "^6.2.4",
"babel-preset-es2015-webpack": "^6.4.2",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    "babel": "^6.5.2",
    "babel-core": "^6.13.2",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.13.2",

Upgrade pakages, after that you may replace deprecated https://github.com/gajus/babel-preset-es2015-webpack on

{
    "presets": [
        [
            "es2015",
            {
                "modules": false
            }
        ]
    ]
}

jmreidy added 3 commits August 9, 2016 15:11
* Switch to npm install format, as suggested by @bebraw
* Update dependencies
* Move explanations inline to the file 
* Switch to new es2015 syntax
@jmreidy
Copy link
Contributor Author

jmreidy commented Aug 9, 2016

Hey all - thanks for the feedback! I've begun integrating the changes suggested here, and will update you when they're complete.

Previously, the config had been split between the config.js file and the CLI; everything has been moved into the config file.

The explanation for the config entries was moved inline, as comments.
@jmreidy
Copy link
Contributor Author

jmreidy commented Aug 11, 2016

Docs are updated. If the review looks good, I'll rebase to a single commit.

@tleunen, could you try using the updated example information and see if it works?

@tleunen
Copy link

tleunen commented Aug 11, 2016

I was already using the same configuration, for the presets. So I updated every dependency again and now the error is a bit different.

I both tested the normal webpack and the webpack-dev-server.

webpack runs fine, and the generated code works perfectly. (at least from what I saw).

The problem comes from webpack-dev-server. With or without the hot reload, it fails at the same place. But the error is a bit different though.
screen shot 2016-08-11 at 4 34 41 pm

There's somewhere a call to __webpack_require__(request) with an undefined request. Not sure why :/ Always when loading something in react-proxy/node_modules/lodash it seems

@@ -0,0 +1,258 @@
---
title: How to Configure Hot Module Replacement?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cc @bebraw

I think since there are many different HMR recipes, maybe we could structure this in like How-To -> HMR Recipies -> Babel/React/Redux

I think that way we encourage other recipes in here for many state libraries and frameworks. And it reinforces a much asked 'cookbook' for certain topics.

@tleunen
Copy link

tleunen commented Aug 11, 2016

@jmreidy I went through your entire guide again and in fact I had missed one important detail...
I forgot to import the AppContainer and wrap my app with it ;)
import { AppContainer } from 'react-hot-loader'

@TheLarkInn
Copy link
Member

@tleunen was it something easily missed or do you think it could be stated better. It's things like this which I believe help developers from getting tripped up.

@tleunen
Copy link

tleunen commented Aug 11, 2016

To be honest, the first time I read it was quite in diagonal. And the setup for rendering the component was very similar to what I already had in my application so I just missed the fact "AppContainer" was something specific to add.
But after re-reading it, I noticed it. I believe adding a quick comment could help because it's the only part of the documentation that has not any comment so it could be easy to miss the fact it's required for the hot reload.

Maybe something like:

// Render the Application inside the Hot Reload AppContainer
ReactDOM.render(
    <AppContainer>
      <App/>
    </AppContainer>,
    document.getElementById('root')
);

@jmreidy
Copy link
Contributor Author

jmreidy commented Aug 12, 2016

@tleunen @TheLarkInn Yeah, I think I should update the docs with both an inline comment and a note. AppContainer is such a generic name that it's easy to gloss over it.

@TheLarkInn @bebraw I like the idea of breaking this out into a specific HMR with React and CSS Modules thread. Do you think there'd be a benefit of structuring it with the actual source code? And switching this guide into a README.md for that code? That way, people could both read the docs AND fire it up in an editor.

@bebraw
Copy link
Contributor

bebraw commented Aug 12, 2016

@jmreidy Maybe we'll end up with articles like this:

  • concepts/hot-module-reloading - Something like this Stack Overflow answer.
  • how-to/set-up-hmr-with-react (just an example) - There can be more specific how tos like this.
  • how-to/set-up-hmr-with-redux (simple setup, but good to mention)
  • api/hot-module-reloading - Literally the HMR interface.

These can cross reference to each other.

@andreypopp
Copy link

I'd advice to have an example wit HMR without react-hot-loader. It's not yet finished according to its author (Dan Abramov) and Webpack HMR works fine with React on its own (you lose preserving React state and DOM but that's not really too bad).

@jmreidy
Copy link
Contributor Author

jmreidy commented Aug 19, 2016

I like @bebraw's idea of making this a specific example of HMR working with React. Shold I close this PR in favor of switching it to a how-to/set-up-hmr-with-reach doc?

@TheLarkInn
Copy link
Member

we will have a general documentation page for just hmr too.

@TheLarkInn
Copy link
Member

You don't have to close the PR. Just go ahead and create the how-to folder if it doesn't already exist, and if it does drop the file in there instead.

@ericclemmons
Copy link

@TheLarkInn pinged me on Twitter about this, and I think Webpack on the server + HMR is worthy of a post. Having "recipes" (like those listed above) would be good to answer HMR for each situation so that users, such as myself, can see how it all works together.

https://github.com/ericclemmons/webpack-hot-server-example

@bebraw
Copy link
Contributor

bebraw commented Aug 30, 2016

@jmreidy Ready to review again? Do you have anything else in mind for this PR?

@jmreidy
Copy link
Contributor Author

jmreidy commented Aug 30, 2016

IMO it's ready to go!

On Tue, Aug 30, 2016 at 10:08 AM Juho Vepsäläinen [email protected]
wrote:

@jmreidy https://github.com/jmreidy Ready to review again? Do you have
anything else in mind for this PR?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#64 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AACMbRv-ZZRgIa40yVwE3o_PWZ7XCeneks5qlGIJgaJpZM4JeKLy
.

@bebraw bebraw merged commit 6177520 into webpack:develop Aug 31, 2016
@bebraw
Copy link
Contributor

bebraw commented Aug 31, 2016

Thanks!

I split up related issues: #85 (concept), #86 (API), #88 (Redux how to).

sallar pushed a commit to sallar/webpack.js.org that referenced this pull request Oct 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants