-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Conversation
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! |
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.
/s/partiular/particular
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.
Add link to "open up a PR".
Thanks a lot @jmreidy for the guide! It helped me a lot. I have an issue though, when trying to execute this code: |
"babel": "^6.5.2", | ||
"babel-core": "^6.11.4", | ||
"babel-loader": "^6.2.4", | ||
"babel-preset-es2015-webpack": "^6.4.2", |
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.
"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
}
]
]
}
* Switch to npm install format, as suggested by @bebraw * Update dependencies
* Move explanations inline to the file * Switch to new es2015 syntax
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.
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? |
@@ -0,0 +1,258 @@ | |||
--- | |||
title: How to Configure Hot Module Replacement? |
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.
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.
@jmreidy I went through your entire guide again and in fact I had missed one important detail... |
@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. |
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. Maybe something like: // Render the Application inside the Hot Reload AppContainer
ReactDOM.render(
<AppContainer>
<App/>
</AppContainer>,
document.getElementById('root')
); |
@tleunen @TheLarkInn Yeah, I think I should update the docs with both an inline comment and a note. @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. |
@jmreidy Maybe we'll end up with articles like this:
These can cross reference to each other. |
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). |
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? |
we will have a general documentation page for just hmr too. |
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. |
@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.
|
@jmreidy Ready to review again? Do you have anything else in mind for this PR? |
IMO it's ready to go! On Tue, Aug 30, 2016 at 10:08 AM Juho Vepsäläinen [email protected]
|
Content - howto hmr
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.