1 | const { safeGet } = require("./projectHelpers");
|
2 |
|
3 | const LAZY_RESOURCE_CONTEXT = "$$_lazy_route_resource";
|
4 | const HOT_SELF_ACCEPT = "module.hot.accept();";
|
5 | const HOT_DISPOSE = `
|
6 | module.hot.dispose(() => {
|
7 | // Currently the context is needed only for application style modules.
|
8 | const moduleContext = {};
|
9 | global.hmrRefresh(moduleContext);
|
10 | });`;
|
11 | const HMR_HANDLER = `
|
12 | if (module.hot) {
|
13 | ${HOT_SELF_ACCEPT}${HOT_DISPOSE}
|
14 | }
|
15 | `;
|
16 |
|
17 | const isLazyLoadedNgModule = resource => {
|
18 | const issuer = safeGet(resource, "issuer");
|
19 | const issuerContext = safeGet(issuer, "context");
|
20 |
|
21 | return issuerContext && issuerContext.endsWith(LAZY_RESOURCE_CONTEXT);
|
22 | };
|
23 |
|
24 | module.exports = function (source, map) {
|
25 | const modifiedSource = isLazyLoadedNgModule(this._module) ?
|
26 | `${source};${HMR_HANDLER}`:
|
27 | source;
|
28 |
|
29 | this.callback(null, modifiedSource, map);
|
30 | };
|