Skip to content

HMR & its dependent environment variable #31

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

Merged
merged 1 commit into from
Jul 31, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,31 @@ Keep in mind, by default `[name].css` is used when `process.env.NODE_ENV === 'de
The 2 exceptions are: `allChunks` will no longer do anything, and `fallback` will no longer do anything when passed to to `extract`. Basically just worry about passing your `css-loader` string and `localIdentName` 🤓


### HMR Pitfall

The most common workflow when working with webpack is to write a "development" / "production" value in to the
'process.env.NODE_ENV' namespace, typically, using webpack's built-in "DefinePlugin" plugin. e.g:

```javascript
new webpack.DefinePlugin( {
'process.env': {
NODE_ENV: `"${config.devMode ? 'development' : 'production'}"`,
},
} )
```
The value set by the aformentioned plugin will only be available in the runtime ( when webpack's javascript output is excuted ).
In order for this plugin to work with hot module reloading, The npm script / gulp task / grunt task etc, should be invoked with the same environment variable as shown above.

For example, when running the build using some form of npm script:

```json
{
"scripts": {
"build": "cross-env NODE_ENV=development webpack --config build/webpack.config.js"
}
}
```
[cross-env](https://www.npmjs.com/package/cross-env) is optional but recomanded

## What about Aphrodite, Glamor, StyleTron, Styled-Components, Styled-Jsx, etc?

Expand Down Expand Up @@ -226,4 +249,3 @@ We use [commitizen](https://github.com/commitizen/cz-cli), so run `npm run cm` t

## More from FaceySpacey in Reactlandia
- [redux-first-router](https://github.com/faceyspacey/redux-first-router). It's made to work perfectly with *Universal*. Together they comprise our *"frameworkless"* Redux-based approach to what Next.js does (splitting, SSR, prefetching, and routing). *People are lovin it by the way* 😎