If you follow the downgradeModule
strategy, it is possible. Upgrading for Performance
You can basically follow this guide to enable HMR, except creating hmr.ts
and the manipulation of the main.ts
, as you do not use it in downgradeModule
strategy.
Much more you activate hmr in the AngularJs main module like this:
// import all libs you need to boot
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {downgradeModule} from '@angular/upgrade/static';
import {MyAngularSevenModule} from "./my-angular-seven.module";
import {environment} from './environments/environment';
import {enableProdMode} from '@angular/core';
// important!: rename angular.module to not conflict with global `module`
import {module as angularModule, element, bootstrap} from 'angular';
// check if in prod mode
if(environment.production) {
enableProdMode();
}
// bootstrap you new Angular 7 main module
const bootstrapFn = (extraProviders) => {
const platformRef = platformBrowserDynamic(extraProviders);
return platformRef.bootstrapModule(MyAngularSevenModule);
};
const downgradedModule = downgradeModule(bootstrapFn);
// check if hmr should be enables and accept it if possible
if(environment.hmr) {
if(module && module.hot) {
module.hot.accept();
}
}
// construct your AngularJs module
const ngModule = angularModule("app", []);
// important!: manually bootstrap AngularJs
element(() => {
try {
bootstrap(document, ['app']);
} catch(error) {
}
});