Skip to content

Commit

Permalink
Support envPrefix in Astro config (#5852)
Browse files Browse the repository at this point in the history
* Support envPrefix in Astro config

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

Co-authored-by: Nate Moore <[email protected]>

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

Co-authored-by: Nate Moore <[email protected]>

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

Co-authored-by: Nate Moore <[email protected]>

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

Co-authored-by: Nate Moore <[email protected]>

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

Co-authored-by: Nate Moore <[email protected]>

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

Co-authored-by: Nate Moore <[email protected]>
  • Loading branch information
Rishi Raj Jain and natemoo-re authored Jan 13, 2023
1 parent ca22a81 commit 3a00ecb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-llamas-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Respect `vite.envPrefix` if provided
4 changes: 2 additions & 2 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -230,7 +230,7 @@ async function clientBuild(
}),
...(viteConfig.plugins || []),
],
envPrefix: 'PUBLIC_',
envPrefix: viteConfig.envPrefix ?? 'PUBLIC_',
base: settings.config.base,
};

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3a00ecb

Please sign in to comment.