diff --git a/.changeset/twenty-llamas-type.md b/.changeset/twenty-llamas-type.md new file mode 100644 index 000000000..34b74888d --- /dev/null +++ b/.changeset/twenty-llamas-type.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Respect `vite.envPrefix` if provided diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index deb8a0b05..561b24372 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -161,7 +161,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp // SSR needs to be last ssr && vitePluginSSR(internals, settings.adapter!), ], - envPrefix: 'PUBLIC_', + envPrefix: viteConfig.envPrefix ?? 'PUBLIC_', base: settings.config.base, }; @@ -230,7 +230,7 @@ async function clientBuild( }), ...(viteConfig.plugins || []), ], - envPrefix: 'PUBLIC_', + envPrefix: viteConfig.envPrefix ?? 'PUBLIC_', base: settings.config.base, }; diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 06c2e8bb0..7f3c18824 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -110,7 +110,7 @@ export async function createVite( ], publicDir: fileURLToPath(settings.config.publicDir), root: fileURLToPath(settings.config.root), - envPrefix: 'PUBLIC_', + envPrefix: settings.config.vite?.envPrefix ?? 'PUBLIC_', define: { 'import.meta.env.SITE': settings.config.site ? JSON.stringify(settings.config.site)