Support envPrefix in Astro config (#5852)

* Support envPrefix in Astro config

* Update packages/astro/src/core/config/schema.ts

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>

* Update packages/astro/src/core/build/static-build.ts

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>

* Update packages/astro/src/core/build/static-build.ts

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>

* Update packages/astro/src/core/config/schema.ts

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>

* Update packages/astro/src/core/create-vite.ts

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>

* Update .changeset/twenty-llamas-type.md

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
Rishi Raj Jain 2023-01-14 02:27:53 +05:30 committed by GitHub
parent ca22a81799
commit 3a00ecb3eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Respect `vite.envPrefix` if provided

View file

@ -161,7 +161,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
// SSR needs to be last // SSR needs to be last
ssr && vitePluginSSR(internals, settings.adapter!), ssr && vitePluginSSR(internals, settings.adapter!),
], ],
envPrefix: 'PUBLIC_', envPrefix: viteConfig.envPrefix ?? 'PUBLIC_',
base: settings.config.base, base: settings.config.base,
}; };
@ -230,7 +230,7 @@ async function clientBuild(
}), }),
...(viteConfig.plugins || []), ...(viteConfig.plugins || []),
], ],
envPrefix: 'PUBLIC_', envPrefix: viteConfig.envPrefix ?? 'PUBLIC_',
base: settings.config.base, base: settings.config.base,
}; };

View file

@ -110,7 +110,7 @@ export async function createVite(
], ],
publicDir: fileURLToPath(settings.config.publicDir), publicDir: fileURLToPath(settings.config.publicDir),
root: fileURLToPath(settings.config.root), root: fileURLToPath(settings.config.root),
envPrefix: 'PUBLIC_', envPrefix: settings.config.vite?.envPrefix ?? 'PUBLIC_',
define: { define: {
'import.meta.env.SITE': settings.config.site 'import.meta.env.SITE': settings.config.site
? JSON.stringify(settings.config.site) ? JSON.stringify(settings.config.site)