diff --git a/src/content/docs/en/guides/environment-variables.mdx b/src/content/docs/en/guides/environment-variables.mdx index 76be72036acb1..8e057eb96357e 100644 --- a/src/content/docs/en/guides/environment-variables.mdx +++ b/src/content/docs/en/guides/environment-variables.mdx @@ -71,8 +71,6 @@ const isDev = import.meta.env.DEV; ### `.env` files Environment variables can be loaded from `.env` files in your project directory. -You can also attach a mode (either `production` or `development`) to the filename, like `.env.production` or `.env.development`, which makes the environment variables only take effect in that mode. - Just create a `.env` file in the project directory and add some variables to it. ```ini title=".env" @@ -82,6 +80,23 @@ DB_PASSWORD="foobar" PUBLIC_POKEAPI="https://pokeapi.co/api/v2" ``` +You can also add `.production`, `.development` or a custom mode name to the filename itself (e.g `env.testing`, `.env.staging`). This allows you to use different sets of environment variables at different times. + +The `astro dev` and `astro build` commands default to `"development"` and `"production"` modes, respectively. You can run these commands with the [`--mode` flag](#--mode-string) to pass a different value for `mode` and load the matching `.env` file. + +This allows you to run the dev server or build your site connecting to different APIs: + +```bash +# Run the dev server connected to a "staging" API +astro dev --mode staging + +# Build a site that connects to a "production" API with additional debug information +astro build --devOutput + +# Build a site that connects to a "testing" API +astro build --mode testing +``` + For more on `.env` files, [see the Vite documentation](https://vite.dev/guide/env-and-mode.html#env-files). ### Using the CLI diff --git a/src/content/docs/en/reference/cli-reference.mdx b/src/content/docs/en/reference/cli-reference.mdx index 2c60d0c63ac0d..8393756fc5431 100644 --- a/src/content/docs/en/reference/cli-reference.mdx +++ b/src/content/docs/en/reference/cli-reference.mdx @@ -146,7 +146,15 @@ Runs Astro's development server. This is a local HTTP server that doesn't bundle Builds your site for deployment. By default, this will generate static files and place them in a `dist/` directory. If [SSR is enabled](/en/guides/on-demand-rendering/), this will generate the necessary server files to serve your site. -Can be combined with the [common flags](#common-flags) documented below. +### Flags + +The command accepts [common flags](#common-flags) and the following additional flags: + +#### `--devOutput` + +
-**Type:** `"development" | "production"`
-**Default:** `"development"` when running `astro dev`, `"production"` when running `astro build`
+**Type:** `string`
+**Default:** `"development"` when running `astro dev`, `"production"` when running `astro build`
+