|
4 | 4 | contributors:
|
5 | 5 | - jmreidy
|
6 | 6 | - jhnns
|
| 7 | + - sararubin |
7 | 8 | ---
|
8 | 9 |
|
9 | 10 | 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;
|
222 | 223 |
|
223 | 224 | The important thing to note in the code above is the `module` reference.
|
224 | 225 |
|
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 }`; |
226 | 227 |
|
227 | 228 | 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.
|
228 | 229 |
|
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: |
230 | 231 |
|
231 | 232 | ```
|
232 | 233 | ["es2015", {"modules": false}]
|
233 | 234 | ```
|
234 | 235 |
|
235 | 236 | 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)).
|
236 | 237 |
|
| 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 | + |
237 | 242 | 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`.
|
238 | 243 |
|
239 | 244 | ### index.html
|
|
0 commit comments