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

Commit 95ec9ff

Browse files
committed
fix(Angular): add hot loader for lazy loaded NgModules
1 parent 8623875 commit 95ec9ff

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lazy-ngmodule-hot-loader.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { safeGet } = require("./projectHelpers");
2+
3+
const LAZY_RESOURCE_CONTEXT = "$$_lazy_route_resource";
4+
const HOT_SELF_ACCEPT = "module.hot && module.hot.accept()";
5+
6+
const isLazyLoadedNgModule = resource => {
7+
const issuer = safeGet(resource, "issuer");
8+
const issuerContext = safeGet(issuer, "context");
9+
10+
return issuerContext && issuerContext.endsWith(LAZY_RESOURCE_CONTEXT);
11+
};
12+
13+
module.exports = function (source) {
14+
return isLazyLoadedNgModule(this._module) ?
15+
`${source};${HOT_SELF_ACCEPT}`:
16+
source;
17+
};

templates/webpack.angular.js

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ module.exports = env => {
192192
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
193193
use: [
194194
"nativescript-dev-webpack/moduleid-compat-loader",
195+
"nativescript-dev-webpack/lazy-ngmodule-hot-loader",
195196
"@ngtools/webpack",
196197
]
197198
},

0 commit comments

Comments
 (0)