Skip to content
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
8 changes: 8 additions & 0 deletions packages/angular/build/src/builders/application/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ interface InternalOptions {
*/
externalRuntimeStyles?: boolean;

/**
* Enables the AOT compiler to generate template component update functions.
* This option is only intended to be used with a development server that can process and serve component
* template updates.
*/
templateUpdates?: boolean;

/**
* Enables instrumentation to collect code coverage data for specific files.
*
Expand Down Expand Up @@ -463,6 +470,7 @@ export async function normalizeOptions(
externalRuntimeStyles,
instrumentForCoverage,
security,
templateUpdates: !!options.templateUpdates,
};
}

Expand Down
10 changes: 9 additions & 1 deletion packages/angular/build/src/builders/dev-server/vite-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
createRemoveIdPrefixPlugin,
} from '../../tools/vite/plugins';
import { loadProxyConfiguration, normalizeSourceMaps } from '../../utils';
import { useComponentStyleHmr } from '../../utils/environment-options';
import { useComponentStyleHmr, useComponentTemplateHmr } from '../../utils/environment-options';
import { loadEsmModule } from '../../utils/load-esm';
import { Result, ResultFile, ResultKind } from '../application/results';
import {
Expand Down Expand Up @@ -145,6 +145,14 @@ export async function* serveWithVite(
void loadEsmModule('@angular/compiler');
}

// Enable to support component template hot replacement (`NG_HMR_TEMPLATE=1` can be used to enable)
browserOptions.templateUpdates = !!serverOptions.liveReload && useComponentTemplateHmr;
if (browserOptions.templateUpdates) {
context.logger.warn(
'Experimental support for component template hot replacement has been enabled via the "NG_HMR_TEMPLATE" environment variable.',
);
}

// Setup the prebundling transformer that will be shared across Vite prebundling requests
const prebundleTransformer = new JavaScriptTransformer(
// Always enable JIT linking to support applications built with and without AOT.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface CompilerPluginOptions {
incremental: boolean;
externalRuntimeStyles?: boolean;
instrumentForCoverage?: (request: string) => boolean;
templateUpdates?: boolean;
}

// eslint-disable-next-line max-lines-per-function
Expand Down Expand Up @@ -656,6 +657,7 @@ function createCompilerOptionsTransformer(
sourceRoot: undefined,
preserveSymlinks,
externalRuntimeStyles: pluginOptions.externalRuntimeStyles,
_enableHmr: pluginOptions.templateUpdates,
};
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function createCompilerPluginOptions(
jit,
externalRuntimeStyles,
instrumentForCoverage,
templateUpdates,
} = options;
const incremental = !!options.watch;

Expand All @@ -40,5 +41,6 @@ export function createCompilerPluginOptions(
incremental,
externalRuntimeStyles,
instrumentForCoverage,
templateUpdates,
};
}
4 changes: 4 additions & 0 deletions packages/angular/build/src/utils/environment-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ const hmrComponentStylesVariable = process.env['NG_HMR_CSTYLES'];
export const useComponentStyleHmr =
!isPresent(hmrComponentStylesVariable) || !isDisabled(hmrComponentStylesVariable);

const hmrComponentTemplateVariable = process.env['NG_HMR_TEMPLATES'];
export const useComponentTemplateHmr =
isPresent(hmrComponentTemplateVariable) && isEnabled(hmrComponentTemplateVariable);

const partialSsrBuildVariable = process.env['NG_BUILD_PARTIAL_SSR'];
export const usePartialSsrBuild =
isPresent(partialSsrBuildVariable) && isEnabled(partialSsrBuildVariable);