1 | module.exports = function (source) {
|
2 | this.cacheable();
|
3 | const { angular = false, loadCss = true, registerModules = /(root|page)\.(xml|css|js|ts|scss)$/ } = this.query;
|
4 |
|
5 | const hmr = `
|
6 | if (module.hot) {
|
7 | const hmrUpdate = require("nativescript-dev-webpack/hmr").hmrUpdate;
|
8 | global.__initialHmrUpdate = true;
|
9 | global.__hmrSyncBackup = global.__onLiveSync;
|
10 |
|
11 | global.__onLiveSync = function () {
|
12 | hmrUpdate();
|
13 | };
|
14 |
|
15 | global.hmrRefresh = function({ type, path } = {}) {
|
16 | if (global.__initialHmrUpdate) {
|
17 | return;
|
18 | }
|
19 |
|
20 | setTimeout(() => {
|
21 | global.__hmrSyncBackup({ type, path });
|
22 | });
|
23 | };
|
24 |
|
25 | hmrUpdate().then(() => {
|
26 | global.__initialHmrUpdate = false;
|
27 | })
|
28 | }
|
29 | `;
|
30 |
|
31 | source = `
|
32 | require("tns-core-modules/bundle-entry-points");
|
33 | ${source}
|
34 | `;
|
35 |
|
36 | if (angular) {
|
37 | source = `
|
38 | ${hmr}
|
39 | ${source}
|
40 | `;
|
41 | } else if (registerModules) {
|
42 | source = `
|
43 | ${hmr}
|
44 | const context = require.context("~/", true, ${registerModules});
|
45 | global.registerWebpackModules(context);
|
46 | ${source}
|
47 | `;
|
48 | }
|
49 |
|
50 | if (loadCss) {
|
51 | source = `
|
52 | require("${
|
53 | angular ?
|
54 | 'nativescript-dev-webpack/load-application-css-angular' :
|
55 | 'nativescript-dev-webpack/load-application-css-regular'
|
56 | }")();
|
57 | ${source}
|
58 | `;
|
59 | }
|
60 |
|
61 | this.callback(null, source);
|
62 | };
|