Skip to main content

$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:

For example, given the following build time environment:

ENVIRONMENT=production
PUBLIC_BASE_URL=http://site.com

With 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 build

The 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