Skip to content

Instantly share code, notes, and snippets.

@MakeHoney
Last active October 9, 2019 10:45
Show Gist options
  • Save MakeHoney/d40a4547908e6c8e15b1fb4e017c68e7 to your computer and use it in GitHub Desktop.
Save MakeHoney/d40a4547908e6c8e15b1fb4e017c68e7 to your computer and use it in GitHub Desktop.
webpack-hot-module-replacement
// 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