Skip to content

Latest commit

 

History

History
45 lines (34 loc) · 837 Bytes

README.md

File metadata and controls

45 lines (34 loc) · 837 Bytes

Webpack ESM HRM

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);
  });
}

For Babel users

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"]
  }
}

Usage

yarn
yarn watch
# then open localhost:8080

License

MIT