Skip to content

Commit cc1dfd4

Browse files
authored
Merge pull request #560 from sararubin/patch-2
Update hmr-react.md
2 parents 45cfeef + 4aef38a commit cc1dfd4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

content/guides/hmr-react.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ sort: 8
44
contributors:
55
- jmreidy
66
- jhnns
7+
- sararubin
78
---
89

910
As explained in detail on the [concept page](/concepts/hot-module-replacement), Hot Module Replacement (HMR) exchanges, adds, or removes modules while an application is running without a page reload.
@@ -222,18 +223,22 @@ export default App;
222223

223224
The important thing to note in the code above is the `module` reference.
224225

225-
1. Webpack will expose `module.hot` to our code since we set `devServer: { hot: true }`;
226+
1. webpack will expose `module.hot` to our code since we set `devServer: { hot: true }`;
226227

227228
2. Thus we can use the `module.hot` hook to enable HMR for specific resources (Here's `App.js`). The most important API here is `module.hot.accept`, which specifies how to handle changes to specific dependencies.
228229

229-
3. Note that because Webpack 2 has built-in support for ES2015 modules, you won't need to re-require your root component in `module.hot.accept`. To make this work, you need to change the Babel ES2015 preset in `.babelrc` to be:
230+
3. Note that because webpack 2 has built-in support for ES2015 modules, you won't need to re-require your root component in `module.hot.accept`. To make this work, you need to change the Babel ES2015 preset in `.babelrc` to be:
230231

231232
```
232233
["es2015", {"modules": false}]
233234
```
234235

235236
like what we did in [Babel Config](#babel-config). Note that disabling Babel's module plugin is not only necessary for HMR. If you don't disable it you'll run into many other issues (see [Migrating from v1 to v2](/guides/migrating/#mixing-es2015-with-amd-and-commonjs) and [webpack-tree-shaking](http://www.2ality.com/2015/12/webpack-tree-shaking.html)).
236237

238+
4. Note that if you're using ES6 modules in your webpack 2 configuration file, and you change your `.babelrc` file in #3 above, you either need to use `require` or create two `.babelrc` files (issue [here](https://github.com/webpack/webpack.js.org/issues/154)):
239+
* One in the project root directory with `"presets": ["es2015"]
240+
* One in the home directory for webpack to build. For this example, in `src/`.
241+
237242
So in this case, `module.hot.accept` will fire the `render` method whenever `src/components/App.js` or its dependencies are changed - which means the `render` method will also fire when the `App.css` is changed, since `App.css` is included in `App.js`.
238243

239244
### index.html

0 commit comments

Comments
 (0)