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) {} .

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e942bb-4726f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e942bb-4726f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?