Skip to content

Instantly share code, notes, and snippets.

@Dok11
Last active June 18, 2019 11:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dok11/cc30759099376d9263fe4edfd0d13341 to your computer and use it in GitHub Desktop.
Save Dok11/cc30759099376d9263fe4edfd0d13341 to your computer and use it in GitHub Desktop.
Angular 6. Instruction for HMR installation
`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