Skip to content

Commit

Permalink
fix(@angular/build): pass define option defined in application buil…
Browse files Browse the repository at this point in the history
…der to Vite prebundling

This update ensures that the `define` option is correctly passed to Vite during the prebundling phase of the application builder, improving compatibility and optimization of the build process.

Closes #29278
  • Loading branch information
alan-agius4 committed Jan 8, 2025
1 parent 48cae81 commit 8639a3b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/angular/build/src/builders/dev-server/vite-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ export async function* serveWithVite(
componentStyles,
templateUpdates,
browserOptions.loader as EsbuildLoaderOption | undefined,
browserOptions.define,
extensions?.middleware,
transformers?.indexHtml,
thirdPartySourcemaps,
Expand Down Expand Up @@ -653,6 +654,7 @@ export async function setupServer(
componentStyles: Map<string, ComponentStyleRecord>,
templateUpdates: Map<string, string>,
prebundleLoaderExtensions: EsbuildLoaderOption | undefined,
define: ApplicationBuilderInternalOptions['define'],
extensionMiddleware?: Connect.NextHandleFunction[],
indexHtmlTransformer?: (content: string) => Promise<string>,
thirdPartySourcemaps = false,
Expand Down Expand Up @@ -765,6 +767,7 @@ export async function setupServer(
target,
loader: prebundleLoaderExtensions,
thirdPartySourcemaps,
define,
}),
},
plugins: [
Expand Down Expand Up @@ -802,6 +805,7 @@ export async function setupServer(
zoneless,
loader: prebundleLoaderExtensions,
thirdPartySourcemaps,
define,
}),
};

Expand Down
3 changes: 3 additions & 0 deletions packages/angular/build/src/tools/vite/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function getDepOptimizationConfig({
ssr,
loader,
thirdPartySourcemaps,
define = {},
}: {
disabled: boolean;
exclude: string[];
Expand All @@ -67,6 +68,7 @@ export function getDepOptimizationConfig({
zoneless: boolean;
loader?: EsbuildLoaderOption;
thirdPartySourcemaps: boolean;
define: Record<string, string> | undefined;
}): DepOptimizationConfig {
const plugins: ViteEsBuildPlugin[] = [
{
Expand Down Expand Up @@ -99,6 +101,7 @@ export function getDepOptimizationConfig({
plugins,
loader,
define: {
...define,
'ngServerMode': `${ssr}`,
},
resolveExtensions: ['.mjs', '.js', '.cjs'],
Expand Down

0 comments on commit 8639a3b

Please sign in to comment.