Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 1163f58

Browse files
committed
refactor(HMR): unify snippet for different flavors
1 parent af55ec6 commit 1163f58

File tree

1 file changed

+6
-31
lines changed

1 file changed

+6
-31
lines changed

Diff for: bundle-config-loader.js

+6-31
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,24 @@ module.exports = function (source) {
33
const { angular = false, loadCss = true, registerModules = /(root|page)\.(xml|css|js|ts|scss)$/ } = this.query;
44

55
const hmr = `
6-
if (module.hot) {
7-
const fileSystemModule = require("tns-core-modules/file-system");
8-
const applicationFiles = fileSystemModule.knownFolders.currentApp();
9-
10-
global.__hmrLivesyncBackup = global.__onLiveSync;
11-
global.__onLiveSync = function () {
12-
console.log("HMR: Sync...");
13-
require("nativescript-dev-webpack/hot")(__webpack_require__.h(), (fileName) => applicationFiles.getFile(fileName));
14-
};
15-
16-
global.__hmrRefresh = function({ type, module }) {
17-
global.__hmrNeedReload = true;
18-
setTimeout(() => {
19-
if(global.__hmrNeedReload) {
20-
global.__hmrNeedReload = false;
21-
global.__hmrLivesyncBackup({ type, module });
22-
}
23-
});
24-
}
25-
26-
global.__hmrInitialSync = true; // needed to determine if we are performing initial sync
27-
global.__onLiveSync();
28-
}
29-
`;
30-
31-
const angularHmr = `
326
if (module.hot) {
337
const hmrUpdate = require("nativescript-dev-webpack/hmr").hmrUpdate;
348
35-
global.__hmrLivesyncBackup = global.__onLiveSync;
9+
global.__hmrLiveSync = global.__onLiveSync;
10+
3611
global.__onLiveSync = function () {
3712
console.log("HMR: Sync...");
3813
hmrUpdate();
3914
};
4015
16+
// global.__hmrSync
4117
global.__hmrRefresh = function({ type, module }) {
4218
setTimeout(() => {
43-
global.__hmrLivesyncBackup({ type, module });
19+
global.__hmrLiveSync({ type, module });
4420
});
4521
};
4622
}
47-
`;
23+
`;
4824

4925
source = `
5026
require("tns-core-modules/bundle-entry-points");
@@ -53,7 +29,7 @@ module.exports = function (source) {
5329

5430
if (angular) {
5531
source = `
56-
${angularHmr}
32+
${hmr}
5733
${source}
5834
`;
5935
} else if (registerModules) {
@@ -78,4 +54,3 @@ module.exports = function (source) {
7854

7955
this.callback(null, source);
8056
};
81-

0 commit comments

Comments
 (0)