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
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,15 @@ export function createServerCodeBundleOptions(
target: string[],
sourceFileCache: SourceFileCache,
): BuildOptions {
const { jit, serverEntryPoint, workspaceRoot, ssrOptions } = options;
const {
jit,
serverEntryPoint,
workspaceRoot,
ssrOptions,
watch,
externalPackages,
prerenderOptions,
} = options;

assert(
serverEntryPoint,
Expand Down Expand Up @@ -194,7 +202,7 @@ export function createServerCodeBundleOptions(
};

buildOptions.plugins ??= [];
if (options.externalPackages) {
if (externalPackages) {
buildOptions.packages = 'external';
} else {
buildOptions.plugins.push(createRxjsEsmResolutionPlugin());
Expand Down Expand Up @@ -225,7 +233,11 @@ export function createServerCodeBundleOptions(
`export { renderApplication, renderModule, ɵSERVER_CONTEXT } from '@angular/platform-server';`,
];

if (options.prerenderOptions?.discoverRoutes) {
if (watch) {
contents.push(`export { ɵresetCompiledComponents } from '@angular/core';`);
}

if (prerenderOptions?.discoverRoutes) {
// We do not import it directly so that node.js modules are resolved using the correct context.
const routesExtractorCode = await readFile(
join(__dirname, '../../utils/routes-extractor/extractor.js'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ export interface MainServerBundleExports {

/** Method to extract routes from the router config. */
extractRoutes: typeof extractRoutes;

ɵresetCompiledComponents?: () => void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,14 @@ export async function renderPage({
ɵSERVER_CONTEXT,
renderModule,
renderApplication,
ɵresetCompiledComponents,
} = await loadBundle('./main.server.mjs');

// Need to clean up GENERATED_COMP_IDS map in `@angular/core`.
// Otherwise an incorrect component ID generation collision detected warning will be displayed in development.
// See: https://github.com/angular/angular-cli/issues/25924
ɵresetCompiledComponents?.();

const platformProviders: StaticProvider[] = [
{
provide: ɵSERVER_CONTEXT,
Expand Down