Skip to content
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

Document how to use react-hot-loader in production #1397

Merged
merged 3 commits into from
Nov 25, 2019

Conversation

silvenon
Copy link
Contributor

Fixes #1104.

@silvenon silvenon changed the title Document that it's ok to use react-hot-loader stuff in production Document how to use react-hot-loader in production Nov 24, 2019
README.md Outdated Show resolved Hide resolved
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`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure --mode production does it. At least there is nothing about this in docs.

Copy link
Contributor Author

@silvenon silvenon Nov 25, 2019

Choose a reason for hiding this comment

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

It does, I tested it. Try it for yourself:

// webpack.config.js
module.exports = {
  entry: './src',
}
// src/index.js
console.log(process.env.NODE_ENV)
yarn add webpack webpack-cli
yarn webapck --mode production
// dist/index.js
// ...among bunch of other stuff...
console.log('production')

@theKashey theKashey merged commit 3c96646 into gaearon:master Nov 25, 2019
@theKashey
Copy link
Collaborator

👍

@silvenon silvenon deleted the docs/production branch November 29, 2019 15:26
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.

Document that react-hot-loader/babel should now be used in production too
2 participants