Angular 2 Hot Module Replacement
Angular2-HMR
This module requires Angular 2.0.0-rc.1 or higher. Please see repository Angular 2 Webpack Starter for a working example.
main.browser.ts
function main(initialHMRstate) {
return bootstrap(App, []);
}
if (isDevelopment) {
let ngHmr = require('angular2-hmr');
ngHmr.hotModuleReplacement(main, module);
} else {
document.addEventListener('DOMContentLoaded', () => main());
}
app.service.ts
import {HmrState} from 'angular2-hmr';
export class AppState {
@HmrState() _state = { };
}
app.component.ts
import {HmrState} from 'angular2-hmr';
@Component({ })
export class App {
@HmrState() localState = {};
}
In production set NODE_ENV
to "production"
to noop HmrState
or strip it from your code
new NormalModuleReplacementPlugin(
/angular2-hmr/,
path.join(__dirname, 'node_modules', 'angular2-hmr', 'prod.js')
),
enjoy — AngularClass
##AngularClass
Learn AngularJS, Angular 2, and Modern Web Development from the best.
Looking for corporate Angular training, want to host us, or Angular consulting? patrick@angularclass.com