similar to CJS, but you don't need to call require again. It's just updated. You may also omit the callback. -- by @wSokra
import {a} from './lib';
if (module.hot) {
module.hot.accept('./lib', function() {
console.log('updated lib');
console.log('then a is:', a);
});
}
HMR breaks in Babel since Babel tranpiled import
syntax. Need to add {modules: false}
in Babel. For example:
{
test: /\.jsx$/,
exclude: /(node_modules)/,
loader: "babel-loader",
query: {
presets: [["env", { modules: false }]],
plugins: ["transform-react-jsx"]
}
}
yarn
yarn watch
# then open localhost:8080
MIT