Skip to content

Commit 8639a3b

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 48cae81 commit 8639a3b

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

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

+4
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,
@@ -765,6 +767,7 @@ export async function setupServer(
765767
target,
766768
loader: prebundleLoaderExtensions,
767769
thirdPartySourcemaps,
770+
define,
768771
}),
769772
},
770773
plugins: [
@@ -802,6 +805,7 @@ export async function setupServer(
802805
zoneless,
803806
loader: prebundleLoaderExtensions,
804807
thirdPartySourcemaps,
808+
define,
805809
}),
806810
};
807811

Diff for: packages/angular/build/src/tools/vite/utils.ts

+3
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)