Skip to content

Commit 941b446

Browse files
committed
feat: source
1 parent a133b1f commit 941b446

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

index.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
var bootstrapModule = /(\.bootstrapModule)\((.+)\)/gm;
2+
3+
function Angular2HMRLoader(source, sourcemap) {
4+
var self = this;
5+
// Not cacheable during unit tests;
6+
self.cacheable && self.cacheable();
7+
8+
source = source.replace(bootstrapModule, function (match, boot, ngmodule, offset, src) {
9+
// return updated metadata
10+
return boot + '(' + ngmodule + ')' +
11+
'.then(function(MODULE_REF: any) {' +
12+
'if (module.hot) {\n'+
13+
'module.hot.accept();\n'+
14+
'\n'+
15+
'if (MODULE_REF.instance.hmrOnInit) {\n'+
16+
'MODULE_REF.instance.hmrOnInit(module.hot.data);\n'+
17+
'}\n'+
18+
'if (MODULE_REF.instance.hmrOnStatus) {\n'+
19+
'module.hot.apply(function(status) {\n'+
20+
'MODULE_REF.instance.hmrOnStatus(status);\n'+
21+
'});\n'+
22+
'}\n'+
23+
'if (MODULE_REF.instance.hmrOnCheck) {\n'+
24+
'module.hot.check(function(err, outdatedModules) {\n'+
25+
'MODULE_REF.instance.hmrOnCheck(err, outdatedModules);\n'+
26+
'});\n'+
27+
'}\n'+
28+
'if (MODULE_REF.instance.hmrOnDecline) {\n'+
29+
'module.hot.decline(function(dependencies) {\n'+
30+
'MODULE_REF.instance.hmrOnDecline(dependencies);\n'+
31+
'});\n'+
32+
'}\n'+
33+
'module.hot.dispose(function(store) {\n'+
34+
'MODULE_REF.instance.hmrOnDestroy && MODULE_REF.instance.hmrOnDestroy(store);\n'+
35+
'MODULE_REF.destroy();\n'+
36+
'MODULE_REF.instance.hmrAfterDestroy && MODULE_REF.instance.hmrAfterDestroy(store);\n'+
37+
' });\n'+
38+
'}\n'+
39+
'return MODULE_REF;\n'+
40+
'})'
41+
});
42+
43+
// Support for tests
44+
if (self.callback) {
45+
self.callback(null, source, sourcemap)
46+
} else {
47+
return source;
48+
}
49+
};
50+
Angular2HMRLoader.default = Angular2HMRLoader;
51+
52+
module.exports = Angular2HMRLoader

0 commit comments

Comments
 (0)