Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular-devkit/build-angular): include HMR accept code in main.ts
This fixes as issue where in some cases the changed module is not accepted which cases the dev-server to fallback to live-reload. This is because the hmr.js and main.ts have different module ids.
- Loading branch information
1 parent
871dd6a
commit 49841f8
Showing
5 changed files
with
303 additions
and
212 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
packages/angular_devkit/build_angular/src/dev-server/hmr_spec.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import { Architect, BuilderRun } from '@angular-devkit/architect'; | ||
import { DevServerBuilderOutput } from '@angular-devkit/build-angular'; | ||
import fetch from 'node-fetch'; // tslint:disable-line:no-implicit-dependencies | ||
import { createArchitect, host } from '../test-utils'; | ||
|
||
|
||
describe('Dev Server Builder hmr', () => { | ||
const target = { project: 'app', target: 'serve' }; | ||
let architect: Architect; | ||
// We use runs like this to ensure it WILL stop the servers at the end of each tests. | ||
let runs: BuilderRun[]; | ||
|
||
beforeEach(async () => { | ||
await host.initialize().toPromise(); | ||
architect = (await createArchitect(host.root())).architect; | ||
runs = []; | ||
}); | ||
afterEach(async () => { | ||
await host.restore().toPromise(); | ||
await Promise.all(runs.map(r => r.stop())); | ||
}); | ||
|
||
it('adds HMR accept code in all JS bundles', async () => { | ||
const run = await architect.scheduleTarget(target, { hmr: true }); | ||
runs.push(run); | ||
const output = await run.result as DevServerBuilderOutput; | ||
expect(output.success).toBe(true); | ||
expect(output.baseUrl).toBe('https://localhost:4200/'); | ||
|
||
const polyfills = await fetch('https://localhost:4200/polyfills.js'); | ||
expect(await polyfills.text()).toContain('ngHmrAccept(module);'); | ||
|
||
const main = await fetch('https://localhost:4200/main.js'); | ||
expect(await main.text()).toContain('ngHmrAccept(module);'); | ||
}, 30000); | ||
}); |
This file contains 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
212 changes: 0 additions & 212 deletions
212
packages/angular_devkit/build_angular/src/webpack/hmr.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.