Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 87f6f19

Browse files
authored
fix-next(Angular): HMR for lazy loaded NgModules (#759)
* fix-next(Angular): HMR for lazy loaded NgModules Currently, the `lazy-ngmodule-hot-loader` [adds](6a9db32) a HMR self-accept to every lazy loaded NgModule during build. After [alignment](fe4abfb) of the HMR lifecycle of NativeScript Angular with non-Angular applications, it requires a handler to update the app after module replacement. * refactor: minor tweaks * Apply suggestions from code review Co-Authored-By: vchimev <[email protected]>
1 parent 0c35c8b commit 87f6f19

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Diff for: lazy-ngmodule-hot-loader.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
const { safeGet } = require("./projectHelpers");
22

33
const LAZY_RESOURCE_CONTEXT = "$$_lazy_route_resource";
4-
const HOT_SELF_ACCEPT = "module.hot && module.hot.accept()";
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+
`;
12+
const HMR_HANDLER = `
13+
if (module.hot) {
14+
${HOT_SELF_ACCEPT}
15+
${HOT_DISPOSE}
16+
}
17+
`;
518

619
const isLazyLoadedNgModule = resource => {
720
const issuer = safeGet(resource, "issuer");
@@ -12,6 +25,6 @@ const isLazyLoadedNgModule = resource => {
1225

1326
module.exports = function (source) {
1427
return isLazyLoadedNgModule(this._module) ?
15-
`${source};${HOT_SELF_ACCEPT}`:
28+
`${source};${HMR_HANDLER}` :
1629
source;
1730
};

0 commit comments

Comments
 (0)