Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add info about --viteMode flag #8016

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/content/docs/en/guides/environment-variables.mdx
Expand Up @@ -17,14 +17,14 @@ PUBLIC_ANYBODY=there
In this example, `PUBLIC_ANYBODY` (accessible via `import.meta.env.PUBLIC_ANYBODY`) will be available in server or client code, while `SECRET_PASSWORD` (accessible via `import.meta.env.SECRET_PASSWORD`) will be server-side only.

:::caution
`.env` files are not loaded inside [configuration files](/en/guides/configuring-astro/#environment-variables).
`.env` files are not loaded inside [configuration files](/en/guides/configuring-astro/#environment-variables).
:::

## Default environment variables

Astro includes a few environment variables out-of-the-box:

- `import.meta.env.MODE`: The mode your site is running in. This is `development` when running `astro dev` and `production` when running `astro build`.
- `import.meta.env.MODE`: The mode your site is running in. By default, this is `development` when running `astro dev` and `production` when running `astro build`. You can override this value using `--viteMode <mode>` CLI flag.
acupofspirt marked this conversation as resolved.
Show resolved Hide resolved
- `import.meta.env.PROD`: `true` if your site is running in production; `false` otherwise.
- `import.meta.env.DEV`: `true` if your site is running in development; `false` otherwise. Always the opposite of `import.meta.env.PROD`.
- `import.meta.env.BASE_URL`: The base url your site is being served from. This is determined by the [`base` config option](/en/reference/configuration-reference/#base).
Expand All @@ -43,7 +43,7 @@ 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.
You can also attach a mode to the filename, like `.env.production` or `.env.staging`, which makes the environment variables only take effect in that mode. By default, Astro loads `.env.development` when running `astro dev` and `.env.production` when running `astro build`. The mode can be configured by passing `--viteMode <mode>` flag to these commands.
acupofspirt marked this conversation as resolved.
Show resolved Hide resolved

Just create a `.env` file in the project directory and add some variables to it.

Expand Down Expand Up @@ -95,7 +95,7 @@ When using SSR, environment variables can be accessed at runtime based on the SS

## IntelliSense for TypeScript

By default, Astro provides type definition for `import.meta.env` in `astro/client.d.ts`.
By default, Astro provides type definition for `import.meta.env` in `astro/client.d.ts`.

While you can define more custom env variables in `.env.[mode]` files, you may want to get TypeScript IntelliSense for user-defined env variables which are prefixed with `PUBLIC_`.

Expand Down
20 changes: 20 additions & 0 deletions src/content/docs/en/reference/cli-reference.mdx
Expand Up @@ -196,12 +196,32 @@ If you started your project using [the `create astro` wizard](/en/install/auto/#

Runs Astro's development server. This is a local HTTP server that doesn't bundle assets. It uses Hot Module Replacement (HMR) to update your browser as you save changes in your editor.

<h3>Flags</h3>

Use these flags to customize the behavior of the command.

#### `--viteMode <mode>`

It defines [mode](https://vitejs.dev/config/shared-options.html#mode) property of the internal Vite config.

<ReadMore>Read more about [Vite modes](https://vitejs.dev/guide/env-and-mode#modes).</ReadMore>
acupofspirt marked this conversation as resolved.
Show resolved Hide resolved

## `astro build`

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/server-side-rendering/), this will generate the necessary server files to serve your site.

Can be combined with the [common flags](#common-flags) documented below.

<h3>Flags</h3>

Use these flags to customize the behavior of the command.

#### `--viteMode <mode>`

It defines [mode](https://vitejs.dev/config/shared-options.html#mode) property of the internal Vite config.

<ReadMore>Read more about [Vite modes](https://vitejs.dev/guide/env-and-mode#modes).</ReadMore>
acupofspirt marked this conversation as resolved.
Show resolved Hide resolved

## `astro preview`

Starts a local server to serve the contents of your static directory (`dist/` by default) created by running `astro build`.
Expand Down