Skip to content

Commit 3c96646

Browse files
authored
Merge pull request #1397 from silvenon/docs/production
Document how to use react-hot-loader in production
2 parents 0bbf33a + 7f498c6 commit 3c96646

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

README.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ Watch
1717
**[Dan Abramov's talk on Hot Reloading with Time Travel](https://www.youtube.com/watch?v=xsSnOQynTHs).**
1818

1919
# Deprecation note
20+
2021
React-Hot-Loader was your friendly neightbour, living outside of React. But it was limiting it's powers and causing not the greatest experience. It's time to make a next step.
2122

22-
__React-Hot-Loader is expected to be replaced by [React Fast Refresh](https://github.com/facebook/react/issues/16604)__. Please remove React-Hot-Loader is Fast Refresh is supported at your environment.
23+
**React-Hot-Loader is expected to be replaced by [React Fast Refresh](https://github.com/facebook/react/issues/16604)**. Please remove React-Hot-Loader if Fast Refresh is supported at your environment.
2324

24-
- `React Native` - [supports Fast Refresh](https://facebook.github.io/react-native/docs/fast-refresh) since 0.61.
25-
- `parcel 2` - [supports Fast Refresh](https://github.com/facebook/react/issues/16604#issuecomment-556082893) since alpha 3.
26-
- `webpack` - no support yet, use React-Hot-Loader
27-
- `other bundler` - no support yet, use React-Hot-Loader
25+
* `React Native` - [supports Fast Refresh](https://facebook.github.io/react-native/docs/fast-refresh) since 0.61.
26+
* `parcel 2` - [supports Fast Refresh](https://github.com/facebook/react/issues/16604#issuecomment-556082893) since alpha 3.
27+
* `webpack` - no support yet, use React-Hot-Loader
28+
* `other bundler` - no support yet, use React-Hot-Loader
2829

2930
## Install
3031

@@ -161,6 +162,20 @@ export default hot(module)(App);
161162
webpack-dev-server --hot
162163
```
163164

165+
## What about production?
166+
167+
The webpack patch, `hot`, Babel plugin, `@hot-loader/react-dom` etc. are all safe to use in production; they leave a minimal footprint, so there is no need to complicate your configuration based on the environment. Using the Babel plugin in production is even recommended because it switches to cleanup mode.
168+
169+
Just ensure that the production mode has been properly set, both as an environment variable and in your bundler. E.g. with webpack you would build your code by running something like:
170+
171+
```
172+
NODE_ENV=production webpack --mode production
173+
```
174+
175+
`NODE_ENV=production` is needed for the Babel plugin, while `--mode production` uses [`webpack.DefinePlugin`](https://webpack.js.org/plugins/define-plugin/) to set `process.env.NODE_ENV` inside the compiled code itself, which is used by `hot` and `@hot-loader/react-dom`.
176+
177+
Make sure to watch your bundle size when implementing react-hot-loader to ensure that you did it correctly.
178+
164179
## Limitations
165180

166181
* (that's the goal) React-Hot-Loader would not change the past, only update the present - no lifecycle event would be called on component update.
@@ -437,7 +452,9 @@ export default hot(Hello); // <-- module will reload itself
437452
Wrapping this root component with `hot()` will ensure that it is hot reloaded correctly.
438453

439454
### Out-of-bound warning
455+
440456
You may see the following warning when code-split components are updated:
457+
441458
```console
442459
React-Hot-Loader: some components were updated out-of-bound. Updating your app to reconcile the changes.
443460
```

0 commit comments

Comments
 (0)