Skip to content

minimal-xyz/minimal-webpack-esm-hmr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

minimal example to HMR Webpack esm code

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published