Skip to content

Commit

Permalink
Document usage in production
Browse files Browse the repository at this point in the history
  • Loading branch information
silvenon committed Nov 24, 2019
1 parent 47e7270 commit 8852fa6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ export default hot(module)(App);
webpack-dev-server --hot
```

## What about production?

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.

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:

```
NODE_ENV=production webpack --mode production
```

`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`.

Make sure to watch your bundle size when implementing react-hot-loader to ensure that you did it correctly.

## Limitations

* (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.
Expand Down

0 comments on commit 8852fa6

Please sign in to comment.