Last active
October 9, 2019 10:45
-
-
Save MakeHoney/d40a4547908e6c8e15b1fb4e017c68e7 to your computer and use it in GitHub Desktop.
webpack-hot-module-replacement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// webpack.config.js | |
module.exports = { | |
... | |
plugins: [ | |
... | |
new webpack.HotModuleReplacementPlugin() | |
... | |
], | |
... | |
devServer: { | |
... | |
hot: true, | |
inline: true, | |
... | |
} | |
} | |
// index.js | |
import React from 'react' | |
import ReactDOM from 'react-dom' | |
import App from './components/App' | |
const render = () => ReactDOM.render(<App />, document.getElementById('root')) | |
render(App) | |
if (module.hot) { | |
module.hot.accept('./components/App', () => render(App)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment