Skip to content

fix(@angular-devkit/build-angular): disable output hashing when running dev-server #19423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions packages/angular_devkit/build_angular/src/dev-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import * as url from 'url';
import * as webpack from 'webpack';
import * as webpackDevServer from 'webpack-dev-server';
import { getAnalyticsConfig, getCompilerConfig } from '../browser';
import { Schema as BrowserBuilderSchema } from '../browser/schema';
import { OutputHashing, Schema as BrowserBuilderSchema } from '../browser/schema';
import { ExecutionTransformer } from '../transforms';
import { BuildBrowserFeatures, normalizeOptimization } from '../utils';
import { findCachePath } from '../utils/cache-path';
Expand Down Expand Up @@ -92,7 +92,7 @@ export function serveWebpackBrowser(
locale: string | undefined;
}> {
// Get the browser configuration from the target name.
const rawBrowserOptions = await context.getTargetOptions(browserTarget);
const rawBrowserOptions = (await context.getTargetOptions(browserTarget)) as json.JsonObject & BrowserBuilderSchema;
options.port = await checkPort(options.port ?? 4200, options.host || 'localhost');

// Override options we need to override, if defined.
Expand Down Expand Up @@ -120,11 +120,18 @@ export function serveWebpackBrowser(
// In dev server we should not have budgets because of extra libs such as socks-js
overrides.budgets = undefined;

if (rawBrowserOptions.outputHashing && rawBrowserOptions.outputHashing !== OutputHashing.None) {
// Disable output hashing for dev build as this can cause memory leaks
// See: https://github.com/webpack/webpack-dev-server/issues/377#issuecomment-241258405
overrides.outputHashing = OutputHashing.None;
logger.warn(`Warning: 'outputHashing' option is disabled when using the dev-server.`);
}

const browserName = await context.getBuilderNameForTarget(browserTarget);
const browserOptions = await context.validateOptions<json.JsonObject & BrowserBuilderSchema>(
const browserOptions = await context.validateOptions(
{ ...rawBrowserOptions, ...overrides },
browserName,
);
) as json.JsonObject & BrowserBuilderSchema;

const { config, projectRoot, i18n } = await generateI18nBrowserWebpackConfigFromContext(
browserOptions,
Expand Down
4 changes: 1 addition & 3 deletions tests/legacy-cli/e2e/tests/basic/ivy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ export default async function() {
}

// Verify it's Ivy.
const mainUrlMatch = body.match(/src="(main\.[a-z0-9]{0,32}\.js)"/);
const mainUrl = mainUrlMatch && mainUrlMatch[1];
const main = await request('http://localhost:4200/' + mainUrl);
const main = await request('http://localhost:4200/main.js');

if (!main.match(/ɵcmp\s*=/) && !main.match(/\\u0275cmp\s*=/)) {
throw new Error('Ivy could not be found.');
Expand Down