Last active
June 18, 2019 11:21
-
-
Save Dok11/cc30759099376d9263fe4edfd0d13341 to your computer and use it in GitHub Desktop.
Angular 6. Instruction for HMR installation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`npm install --save-dev @angularclass/hmr` | |
`src/environments/environment.prod.ts` | |
Add rule: `hmr: false` | |
`src/environments/environment.ts` | |
Add rule: `hmr: true` | |
`package.json` | |
Add flag to serve mode `--hmr` | |
Make setup by documentation: src/hmr.ts, src/main.ts | |
``` | |
import { NgModuleRef, ApplicationRef } from '@angular/core'; | |
import { createNewHosts } from '@angularclass/hmr'; | |
export const hmrBootstrap = (module: any, bootstrap: () => Promise<void|NgModuleRef<any>>) => { | |
let ngModule: NgModuleRef<any>; | |
if (module && module.hot) { | |
module.hot.accept(); | |
bootstrap().then(mod => { | |
if (mod) { | |
ngModule = mod; | |
} | |
}); | |
module.hot.dispose(() => { | |
const appRef: ApplicationRef = ngModule.injector.get(ApplicationRef); | |
const elements = appRef.components.map(c => c.location.nativeElement); | |
const makeVisible = createNewHosts(elements); | |
ngModule.destroy(); | |
makeVisible(); | |
}); | |
} | |
}; | |
``` | |
`/src/tsconfig.app` | |
compilerOptions -> types -> add `"node"` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment