From ba697da4c24c96f2a4b6ed734674691c160e1b28 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Fri, 26 Aug 2022 21:03:22 +0800 Subject: [PATCH] Note private env var handling with cloudflare builds (#4490) --- packages/integrations/cloudflare/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/integrations/cloudflare/README.md b/packages/integrations/cloudflare/README.md index 2ca3bfac5..bb59b5658 100644 --- a/packages/integrations/cloudflare/README.md +++ b/packages/integrations/cloudflare/README.md @@ -55,3 +55,17 @@ In order to work around this: - install the `"web-streams-polyfill"` package - add `import "web-streams-polyfill/es2018";` to the top of the front matter of every page which requires streams, such as server rendering a React component. +## Environment Variables + +As Cloudflare Pages Functions [provides environment variables differently](https://developers.cloudflare.com/pages/platform/functions/#adding-environment-variables-locally), private environment variables needs to be set through [`vite.define`](https://vitejs.dev/config/shared-options.html#define) to work in builds. + +```js +// astro.config.mjs +export default { + vite: { + define: { + 'process.env.MY_SECRET': JSON.stringify(process.env.MY_SECRET), + }, + }, +} +```