Skip to content

Commit cb52eab

Browse files
committed
fix(@angular/build): pass define option defined in application builder 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
1 parent 4000959 commit cb52eab

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

packages/angular/build/src/builders/dev-server/vite-server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ export async function* serveWithVite(
422422
componentStyles,
423423
templateUpdates,
424424
browserOptions.loader as EsbuildLoaderOption | undefined,
425+
browserOptions.define,
425426
extensions?.middleware,
426427
transformers?.indexHtml,
427428
thirdPartySourcemaps,
@@ -653,6 +654,7 @@ export async function setupServer(
653654
componentStyles: Map<string, ComponentStyleRecord>,
654655
templateUpdates: Map<string, string>,
655656
prebundleLoaderExtensions: EsbuildLoaderOption | undefined,
657+
define: ApplicationBuilderInternalOptions['define'],
656658
extensionMiddleware?: Connect.NextHandleFunction[],
657659
indexHtmlTransformer?: (content: string) => Promise<string>,
658660
thirdPartySourcemaps = false,
@@ -754,6 +756,7 @@ export async function setupServer(
754756
target,
755757
loader: prebundleLoaderExtensions,
756758
thirdPartySourcemaps,
759+
define,
757760
}),
758761
},
759762
plugins: [
@@ -791,6 +794,7 @@ export async function setupServer(
791794
zoneless,
792795
loader: prebundleLoaderExtensions,
793796
thirdPartySourcemaps,
797+
define,
794798
}),
795799
};
796800

packages/angular/build/src/tools/vite/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export function getDepOptimizationConfig({
5757
ssr,
5858
loader,
5959
thirdPartySourcemaps,
60+
define = {},
6061
}: {
6162
disabled: boolean;
6263
exclude: string[];
@@ -67,6 +68,7 @@ export function getDepOptimizationConfig({
6768
zoneless: boolean;
6869
loader?: EsbuildLoaderOption;
6970
thirdPartySourcemaps: boolean;
71+
define: Record<string, string> | undefined;
7072
}): DepOptimizationConfig {
7173
const plugins: ViteEsBuildPlugin[] = [
7274
{
@@ -99,6 +101,7 @@ export function getDepOptimizationConfig({
99101
plugins,
100102
loader,
101103
define: {
104+
...define,
102105
'ngServerMode': `${ssr}`,
103106
},
104107
resolveExtensions: ['.mjs', '.js', '.cjs'],

0 commit comments

Comments
 (0)