Skip to content
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

fix(@angular-devkit/build-angular): fully downlevel async/await when using vite dev-server with caching enabled #25986

Merged
Merged
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 @@ -18,8 +18,10 @@ import path, { posix } from 'node:path';
import type { Connect, InlineConfig, ViteDevServer } from 'vite';
import { BuildOutputFile, BuildOutputFileType } from '../../tools/esbuild/bundler-context';
import { JavaScriptTransformer } from '../../tools/esbuild/javascript-transformer';
import { getFeatureSupport, transformSupportedBrowsersToTargets } from '../../tools/esbuild/utils';
import { createAngularLocaleDataPlugin } from '../../tools/vite/i18n-locale-plugin';
import { RenderOptions, renderPage } from '../../utils/server-rendering/render-page';
import { getSupportedBrowsers } from '../../utils/supported-browsers';
import { getIndexOutputFile } from '../../utils/webpack-browser-config';
import { buildEsbuildBrowser } from '../browser-esbuild';
import { Schema as BrowserBuilderOptions } from '../browser-esbuild/schema';
Expand Down Expand Up @@ -131,6 +133,16 @@ export async function* serveWithVite(
if (server) {
handleUpdate(generatedFiles, server, serverOptions, context.logger);
} else {
const projectName = context.target?.project;
if (!projectName) {
throw new Error('The builder requires a target.');
}

const { root = '' } = await context.getProjectMetadata(projectName);
const projectRoot = path.join(context.workspaceRoot, root as string);
const browsers = getSupportedBrowsers(projectRoot, context.logger);
const target = transformSupportedBrowsersToTargets(browsers);

// Setup server and start listening
const serverConfiguration = await setupServer(
serverOptions,
Expand All @@ -140,6 +152,7 @@ export async function* serveWithVite(
browserOptions.externalDependencies,
!!browserOptions.ssr,
prebundleTransformer,
target,
);

server = await createServer(serverConfiguration);
Expand Down Expand Up @@ -295,6 +308,7 @@ export async function setupServer(
prebundleExclude: string[] | undefined,
ssr: boolean,
prebundleTransformer: JavaScriptTransformer,
target: string[],
): Promise<InlineConfig> {
const proxy = await loadProxyConfiguration(
serverOptions.workspaceRoot,
Expand Down Expand Up @@ -556,6 +570,9 @@ export async function setupServer(
entries: [],
// Add an esbuild plugin to run the Angular linker on dependencies
esbuildOptions: {
// Set esbuild supported targets.
target,
supported: getFeatureSupport(target),
plugins: [
{
name: 'angular-vite-optimize-deps',
Expand Down
Loading