This repository was archived by the owner on Aug 7, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathbundle-config-loader.js
58 lines (49 loc) · 1.93 KB
/
bundle-config-loader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module.exports = function (source) {
this.cacheable();
const { angular = false, loadCss = true, registerModules = /(root|page)\.(xml|css|js|ts|scss)$/ } = this.query;
source = `
require("tns-core-modules/bundle-entry-points");
${source}
`;
if (!angular && registerModules) {
const hmr = `
if (module.hot) {
const fileSystemModule = require("tns-core-modules/file-system");
const applicationFiles = fileSystemModule.knownFolders.currentApp();
global.__hmrLivesyncBackup = global.__onLiveSync;
global.__onLiveSync = function () {
console.log("HMR: Sync...");
require("nativescript-dev-webpack/hot")(__webpack_require__.h(), (fileName) => applicationFiles.getFile(fileName));
};
global.__hmrRefresh = function({ type, module }) {
global.__hmrNeedReload = true;
setTimeout(() => {
if(global.__hmrNeedReload) {
global.__hmrNeedReload = false;
global.__hmrLivesyncBackup({ type, module });
}
});
}
global.__hmrInitialSync = true; // needed to determine if we are performing initial sync
global.__onLiveSync();
}
`;
source = `
${hmr}
const context = require.context("~/", true, ${registerModules});
global.registerWebpackModules(context);
${source}
`;
}
if (loadCss) {
source = `
require("${
angular ?
'nativescript-dev-webpack/load-application-css-angular' :
'nativescript-dev-webpack/load-application-css-regular'
}")();
${source}
`;
}
this.callback(null, source);
};