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

[fix] expose Vite.js mode from $app/env #1789

Merged
merged 7 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silly-jokes-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Expose Vite.js mode from \$app/env
3 changes: 2 additions & 1 deletion documentation/docs/05-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ SvelteKit makes a number of modules available to your application.
### $app/env

```js
import { amp, browser, dev, prerendering } from '$app/env';
import { amp, browser, dev, mode, prerendering } from '$app/env';
```

- `amp` is `true` or `false` depending on the corresponding value in your [project configuration](#configuration)
- `browser` is `true` or `false` depending on whether the app is running in the browser or on the server
- `dev` is `true` in development mode, `false` in production
- `mode` is the [Vite mode](https://vitejs.dev/guide/env-and-mode.html#modes), which is `development` in dev mode or `production` during build unless configured otherwise in `config.kit.vite.mode`.
- `prerendering` is `true` when [prerendering](#ssr-and-javascript-prerender), `false` otherwise

### $app/navigation
Expand Down
4 changes: 4 additions & 0 deletions packages/kit/src/runtime/app/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export const browser = !import.meta.env.SSR;
* @type {import('$app/env').dev}
*/
export const dev = !!import.meta.env.DEV;
/**
* @type {import('$app/env').mode}
*/
export const mode = import.meta.env.MODE;
/**
* @type {import('$app/env').amp}
*/
Expand Down
6 changes: 6 additions & 0 deletions packages/kit/types/ambient-modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ declare module '$app/env' {
* `true` when prerendering, `false` otherwise.
*/
export const prerendering: boolean;
/**
* The Vite.js mode the app is running in. Configure in `config.kit.vite.mode`.
* Vite.js loads the dotenv file associated with the provided mode, `.env.[mode]` or `.env.[mode].local`.
* By default, `svelte-kit dev` runs with `mode=development` and `svelte-kit build` runs with `mode=production`.
*/
export const mode: string;
}

declare module '$app/navigation' {
Expand Down