123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import hotEmitter from "webpack/hot/emitter.js";
- import { log } from "./log.js";
- function reloadApp(_ref, status) {
- var hot = _ref.hot,
- liveReload = _ref.liveReload;
- if (status.isUnloading) {
- return;
- }
- var currentHash = status.currentHash,
- previousHash = status.previousHash;
- var isInitial = currentHash.indexOf( previousHash) >= 0;
- if (isInitial) {
- return;
- }
-
- function applyReload(rootWindow, intervalId) {
- clearInterval(intervalId);
- log.info("App updated. Reloading...");
- rootWindow.location.reload();
- }
- var search = self.location.search.toLowerCase();
- var allowToHot = search.indexOf("webpack-dev-server-hot=false") === -1;
- var allowToLiveReload = search.indexOf("webpack-dev-server-live-reload=false") === -1;
- if (hot && allowToHot) {
- log.info("App hot update...");
- hotEmitter.emit("webpackHotUpdate", status.currentHash);
- if (typeof self !== "undefined" && self.window) {
-
- self.postMessage("webpackHotUpdate".concat(status.currentHash), "*");
- }
- }
-
- else if (liveReload && allowToLiveReload) {
- var rootWindow = self;
-
- var intervalId = self.setInterval(function () {
- if (rootWindow.location.protocol !== "about:") {
-
- applyReload(rootWindow, intervalId);
- } else {
- rootWindow = rootWindow.parent;
- if (rootWindow.parent === rootWindow) {
-
- applyReload(rootWindow, intervalId);
- }
- }
- });
- }
- }
- export default reloadApp;
|