mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 02:54:11 +08:00
31 lines
920 B
JavaScript
31 lines
920 B
JavaScript
const { safeGet } = require("./projectHelpers");
|
|
|
|
const LAZY_RESOURCE_CONTEXT = "$$_lazy_route_resource";
|
|
const HOT_SELF_ACCEPT = "module.hot.accept();";
|
|
const HOT_DISPOSE = `
|
|
module.hot.dispose(() => {
|
|
// Currently the context is needed only for application style modules.
|
|
const moduleContext = {};
|
|
global.hmrRefresh(moduleContext);
|
|
});`;
|
|
const HMR_HANDLER = `
|
|
if (module.hot) {
|
|
${HOT_SELF_ACCEPT}${HOT_DISPOSE}
|
|
}
|
|
`;
|
|
|
|
const isLazyLoadedNgModule = resource => {
|
|
const issuer = safeGet(resource, "issuer");
|
|
const issuerContext = safeGet(issuer, "context");
|
|
|
|
return issuerContext && issuerContext.endsWith(LAZY_RESOURCE_CONTEXT);
|
|
};
|
|
|
|
module.exports = function (source, map) {
|
|
const modifiedSource = isLazyLoadedNgModule(this._module) ?
|
|
`${source};${HMR_HANDLER}`:
|
|
source;
|
|
|
|
this.callback(null, modifiedSource, map);
|
|
};
|