Skip to content

Commit 8852fa6

Browse files
committed
Document usage in production
1 parent 47e7270 commit 8852fa6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,20 @@ export default hot(module)(App);
162162
webpack-dev-server --hot
163163
```
164164

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+
165179
## Limitations
166180

167181
* (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.

0 commit comments

Comments
 (0)