From 3a00ecb3eb4bc44be758c064f2bde6e247e8a593 Mon Sep 17 00:00:00 2001 From: Rishi Raj Jain Date: Sat, 14 Jan 2023 02:27:53 +0530 Subject: [PATCH] Support envPrefix in Astro config (#5852) * Support envPrefix in Astro config * Update packages/astro/src/core/config/schema.ts Co-authored-by: Nate Moore * Update packages/astro/src/core/build/static-build.ts Co-authored-by: Nate Moore * Update packages/astro/src/core/build/static-build.ts Co-authored-by: Nate Moore * Update packages/astro/src/core/config/schema.ts Co-authored-by: Nate Moore * Update packages/astro/src/core/create-vite.ts Co-authored-by: Nate Moore * Update .changeset/twenty-llamas-type.md Co-authored-by: Nate Moore --- .changeset/twenty-llamas-type.md | 5 +++++ packages/astro/src/core/build/static-build.ts | 4 ++-- packages/astro/src/core/create-vite.ts | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changeset/twenty-llamas-type.md diff --git a/.changeset/twenty-llamas-type.md b/.changeset/twenty-llamas-type.md new file mode 100644 index 000000000000..34b74888dbd9 --- /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 deb8a0b05c95..561b24372473 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 06c2e8bb05b8..7f3c18824b38 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)