Skip to main content

$env/static/public

This module provides access to environment variables that are injected statically into your bundle at build time and are publicly accessible.

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.

Public access:

  • This module can be imported into client-side code
  • Only variables that begin with config.kit.env.publicPrefix (which defaults to PUBLIC_) are included

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/public';

var console: Consoleconsole.Console.log(...data: any[]): voidlog(import ENVIRONMENTENVIRONMENT); // => throws error during build
var console: Consoleconsole.Console.log(...data: any[]): voidlog(import PUBLIC_BASE_URLPUBLIC_BASE_URL); // => "http://site.com"

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