Webpack hot load problem. The meaning of module.hot.accept () api

if (module.hot) {

// 
module.hot.accept();

}

if (module.hot) {

module.hot.accept("./print.js", function() {
  console.log("Accepting the updated printMe module!");
  printMe();
})

}

what"s the difference between the two, and why the page has different results during hot loading. Here is my page code
import _ from "lodash"
import printMe from". / print"
function component () {

var element = document.createElement("div");
var btn = document.createElement("button");
element.innerHTML = _.join(["Hello", "webpack"], " ");
btn.innerHTML = "Click me and  check the console!";
btn.onclick = printMe;
element.appendChild(btn);
return element;

}
document.body.appendChild (component ())

if (module.hot) {

// 
module.hot.accept();

}

if (module.hot) {

module.hot.accept("./print.js", function() {
  console.log("Accepting the updated printMe module!");
  printMe();
})

}

the result of page update after using the first method is

appendDOM


when you use module.hot.accept , the hot update will only update the corresponding module, not refresh the entire page.


module.hot.accept () receives two parameters, the first is dependency, the second is callback,
1, if no parameter is passed, js will be executed again, so one more line of your element.
2. If a dependency is passed, only the callback corresponding to the dependency will be executed, that is, page refresh will not be written in the following function body

console.log('Accepting the updated printMe module!');
  printMe();

3, if (module.hot) {} .

Menu