Skip to content

Commit

Permalink
[feat] expose Vite.js mode from $app/env (#1789)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
  • Loading branch information
jthegedus and benmccann committed Jul 8, 2021
1 parent 64f749d commit 1ec368a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
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

0 comments on commit 1ec368a

Please sign in to comment.