@angularclass/hmr-loader
Advanced tools
Comparing version 1.0.1 to 2.0.0
103
index.js
@@ -1,3 +0,6 @@ | ||
var bootstrapModule = /(\.bootstrapModule)\((.+)\)/gm; | ||
var utils = require('loader-utils'); | ||
var bootstrapModule = /(\.bootstrapModule|\.bootstrapModuleFactory)\((.+)\)/gm; | ||
var bootLoader = /(hmr_1\.bootloader)\((.+)\)/gm; | ||
function Angular2HMRLoader(source, sourcemap) { | ||
@@ -7,47 +10,75 @@ var self = this; | ||
self.cacheable && self.cacheable(); | ||
var query = utils.parseQuery(self.query); | ||
function done(src, srcmap) { | ||
// Support for tests | ||
if (self.callback) { | ||
self.callback(null, src, srcmap); | ||
} else { | ||
return src; | ||
} | ||
} | ||
if (query.prod) { | ||
source = source.replace(bootLoader, function (match, boot, ngmodule, offset, src) { | ||
// return updated metadata | ||
var newLine = ' '; | ||
if (query.pretty) { | ||
newLine = '\n'; | ||
} | ||
return ';' + | ||
'if (document.readyState === "complete") {'+ newLine + | ||
' ' + ngmodule + '()' + newLine + | ||
'} else {'+ newLine + | ||
' document.addEventListener("DOMContentLoaded", function() { ' + ngmodule + '()' + ' });'+ newLine + | ||
'}'; | ||
}); | ||
return done(source, sourcemap); | ||
} | ||
source = source.replace(bootstrapModule, function (match, boot, ngmodule, offset, src) { | ||
// return updated metadata | ||
var newLine = ' '; | ||
if (query.pretty) { | ||
newLine = '\n'; | ||
} | ||
return boot + '(' + ngmodule + ')' + | ||
'.then(function(MODULE_REF) {' + | ||
'if (module["hot"]) {\n'+ | ||
'module["hot"]["accept"]();\n'+ | ||
'\n'+ | ||
'if (MODULE_REF.instance["hmrOnInit"]) {\n'+ | ||
'MODULE_REF.instance["hmrOnInit"](module["hot"]["data"]);\n'+ | ||
'}\n'+ | ||
'if (MODULE_REF.instance["hmrOnStatus"]) {\n'+ | ||
'module["hot"]["apply"](function(status) {\n'+ | ||
'MODULE_REF.instance["hmrOnStatus"](status);\n'+ | ||
'});\n'+ | ||
'}\n'+ | ||
'if (MODULE_REF.instance["hmrOnCheck"]) {\n'+ | ||
'module["hot"]["check"](function(err, outdatedModules) {\n'+ | ||
'MODULE_REF.instance["hmrOnCheck"](err, outdatedModules);\n'+ | ||
'});\n'+ | ||
'}\n'+ | ||
'if (MODULE_REF.instance["hmrOnDecline"]) {\n'+ | ||
'module["hot"]["decline"](function(dependencies) {\n'+ | ||
'MODULE_REF.instance["hmrOnDecline"](dependencies);\n'+ | ||
'});\n'+ | ||
'}\n'+ | ||
'module["hot"]["dispose"](function(store) {\n'+ | ||
'MODULE_REF.instance["hmrOnDestroy"] && MODULE_REF.instance["hmrOnDestroy"](store);\n'+ | ||
'MODULE_REF.destroy();\n'+ | ||
'MODULE_REF.instance["hmrAfterDestroy"] && MODULE_REF.instance["hmrAfterDestroy"](store);\n'+ | ||
' });\n'+ | ||
'}\n'+ | ||
'return MODULE_REF;\n'+ | ||
'.then(function(MODULE_REF) {'+ newLine + | ||
' if (module["hot"]) {'+ newLine + | ||
' module["hot"]["accept"]();'+ newLine + | ||
' '+ newLine + | ||
' if (MODULE_REF.instance["hmrOnInit"]) {'+ newLine + | ||
' MODULE_REF.instance["hmrOnInit"](module["hot"]["data"]);'+ newLine + | ||
' }'+ newLine + | ||
' if (MODULE_REF.instance["hmrOnStatus"]) {'+ newLine + | ||
' module["hot"]["apply"](function(status) {'+ newLine + | ||
' MODULE_REF.instance["hmrOnStatus"](status);'+ newLine + | ||
' });'+ newLine + | ||
' }'+ newLine + | ||
' if (MODULE_REF.instance["hmrOnCheck"]) {'+ newLine + | ||
' module["hot"]["check"](function(err, outdatedModules) {'+ newLine + | ||
' MODULE_REF.instance["hmrOnCheck"](err, outdatedModules);'+ newLine + | ||
' });'+ newLine + | ||
' }'+ newLine + | ||
' if (MODULE_REF.instance["hmrOnDecline"]) {'+ newLine + | ||
' module["hot"]["decline"](function(dependencies) {'+ newLine + | ||
' MODULE_REF.instance["hmrOnDecline"](dependencies);'+ newLine + | ||
' });'+ newLine + | ||
' }'+ newLine + | ||
' module["hot"]["dispose"](function(store) {'+ newLine + | ||
' MODULE_REF.instance["hmrOnDestroy"] && MODULE_REF.instance["hmrOnDestroy"](store);'+ newLine + | ||
' MODULE_REF.destroy();'+ newLine + | ||
' MODULE_REF.instance["hmrAfterDestroy"] && MODULE_REF.instance["hmrAfterDestroy"](store);'+ newLine + | ||
' });'+ newLine + | ||
' }'+ newLine + | ||
' return MODULE_REF;'+ newLine + | ||
'})' | ||
}); | ||
// Support for tests | ||
if (self.callback) { | ||
self.callback(null, source, sourcemap) | ||
} else { | ||
return source; | ||
} | ||
return done(source, sourcemap) | ||
}; | ||
Angular2HMRLoader.default = Angular2HMRLoader; | ||
module.exports = Angular2HMRLoader |
{ | ||
"name": "@angularclass/hmr-loader", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Angular 2 HMR Webpack Loader by @AngularClass", | ||
@@ -27,3 +27,6 @@ "main": "index.js", | ||
}, | ||
"homepage": "https://github.com/AngularClass/angular2-hmr-loader#readme" | ||
"homepage": "https://github.com/AngularClass/angular2-hmr-loader#readme", | ||
"dependencies": { | ||
"loader-utils": "^0.2.15" | ||
} | ||
} |
# Angular 2 HMR Loader | ||
Angular 2 HMR Webpack Loader by @AngularClass | ||
Please consider using https://github.com/AngularClass/angular2-hmr which provides helpers for HMR in Angular 2 | ||
```es6 | ||
@@ -4,0 +5,0 @@ { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16054
74
13
1
+ Addedloader-utils@^0.2.15
+ Addedbig.js@3.2.0(transitive)
+ Addedemojis-list@2.1.0(transitive)
+ Addedjson5@0.5.1(transitive)
+ Addedloader-utils@0.2.17(transitive)
+ Addedobject-assign@4.1.1(transitive)