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
70 lines (59 loc) · 1.92 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
58
59
60
61
62
63
64
65
66
67
68
69
70
const unitTestingConfigLoader = require("./unit-testing-config-loader");
module.exports = function (source) {
this.cacheable();
const { angular = false, loadCss = true, unitTesting, projectRoot, appFullPath, registerModules = /(root|page)\.(xml|css|js|ts|scss)$/ } = this.query;
if (unitTesting) {
source = unitTestingConfigLoader({ appFullPath, projectRoot, angular, registerModules });
this.callback(null, source);
return;
}
const hmr = `
if (module.hot) {
const hmrUpdate = require("nativescript-dev-webpack/hmr").hmrUpdate;
global.__initialHmrUpdate = true;
global.__hmrSyncBackup = global.__onLiveSync;
global.__onLiveSync = function () {
hmrUpdate();
};
global.hmrRefresh = function({ type, path } = {}) {
if (global.__initialHmrUpdate) {
return;
}
setTimeout(() => {
global.__hmrSyncBackup({ type, path });
});
};
hmrUpdate().then(() => {
global.__initialHmrUpdate = false;
})
}
`;
source = `
require("tns-core-modules/bundle-entry-points");
${source}
`;
if (angular) {
source = `
${hmr}
${source}
`;
} else if (registerModules) {
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);
};