Skip to content

Commit 1f2481a

Browse files
committedJan 8, 2025·
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 (cherry picked from commit 8639a3b)
1 parent 48988ea commit 1f2481a

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

+4
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ export async function* serveWithVite(
390390
componentStyles,
391391
templateUpdates,
392392
browserOptions.loader as EsbuildLoaderOption | undefined,
393+
browserOptions.define,
393394
extensions?.middleware,
394395
transformers?.indexHtml,
395396
thirdPartySourcemaps,
@@ -635,6 +636,7 @@ export async function setupServer(
635636
componentStyles: Map<string, ComponentStyleRecord>,
636637
templateUpdates: Map<string, string>,
637638
prebundleLoaderExtensions: EsbuildLoaderOption | undefined,
639+
define: ApplicationBuilderInternalOptions['define'],
638640
extensionMiddleware?: Connect.NextHandleFunction[],
639641
indexHtmlTransformer?: (content: string) => Promise<string>,
640642
thirdPartySourcemaps = false,
@@ -741,6 +743,7 @@ export async function setupServer(
741743
target,
742744
loader: prebundleLoaderExtensions,
743745
thirdPartySourcemaps,
746+
define,
744747
}),
745748
},
746749
plugins: [
@@ -778,6 +781,7 @@ export async function setupServer(
778781
zoneless,
779782
loader: prebundleLoaderExtensions,
780783
thirdPartySourcemaps,
784+
define,
781785
}),
782786
};
783787

‎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)
Please sign in to comment.