$env/static/private
This module provides access to environment variables that are injected statically into your bundle at build time and are limited to private access.
| Runtime | Build time | |
|---|---|---|
| Private | $env/dynamic/private |
$env/static/private |
| Public | $env/dynamic/public |
$env/static/public |
Static environment variables are loaded by Vite from .env files and process.env at build time and then statically injected into your bundle at build time, enabling optimisations like dead code elimination.
Private access:
- This module cannot be imported into client-side code
- This module only includes variables that do not begin with
config.kit.env.publicPrefixand do start withconfig.kit.env.privatePrefix(if configured)
For example, given the following build time environment:
ENVIRONMENT=production
PUBLIC_BASE_URL=http://site.comWith the default publicPrefix and privatePrefix:
import { import ENVIRONMENTENVIRONMENT, import PUBLIC_BASE_URLPUBLIC_BASE_URL } from '$env/static/private';
var console: Consoleconsole.Console.log(...data: any[]): voidlog(import ENVIRONMENTENVIRONMENT); // => "production"
var console: Consoleconsole.Console.log(...data: any[]): voidlog(import PUBLIC_BASE_URLPUBLIC_BASE_URL); // => throws error during buildThe above values will be the same even if different values for ENVIRONMENT or PUBLIC_BASE_URL are set at runtime, as they are statically replaced in your code with their build time values.
Edit this page on GitHub llms.txt
previous next