Menu

Environment Configuration

Relevant source files

Purpose and Scope

This document describes the environment configuration system used by the Excalidraw application, focusing on the .env.development and .env.production files and the VITE_APP_* environment variables that control backend service URLs, feature flags, and debugging options. This configuration applies specifically to the excalidraw-app hosted application.

For backend service integration details, see Backend Service Configuration. For analytics-specific configuration, see Analytics and Monitoring. For PWA configuration, see PWA and Offline Support.

Environment File Structure

Excalidraw uses Vite's environment variable system with separate configuration files for different deployment contexts. The environment files are located at the repository root and follow Vite's standard naming conventions.

Sources: .env.development1-56 .env.production1-35

File Loading Order

Vite loads environment files in the following priority order (highest priority first):

  1. .env.[mode].local (e.g., .env.development.local) - gitignored
  2. .env.local - gitignored for all modes except test
  3. .env.[mode] (e.g., .env.development)
  4. .env - base configuration (not used in Excalidraw)

Variables defined in files with higher priority override those in lower priority files. The .env.local files are explicitly gitignored to prevent committing sensitive configuration.

Sources: .env.development19-20

Variable Naming Convention

All environment variables accessible in the application must be prefixed with VITE_APP_ to be embedded in the client-side bundle. This is a Vite security feature that prevents accidentally exposing server-side environment variables to the client.

Sources: .env.development3-15 packages/excalidraw/vite-env.d.ts5-56

Environment Variable Categories

Backend Service URLs

These variables configure the URLs for external backend services used by the application.

VariableDevelopment ValueProduction ValuePurpose
VITE_APP_BACKEND_V2_GET_URLhttps://json-dev.excalidraw.com/api/v2/https://json.excalidraw.com/api/v2/Scene retrieval endpoint
VITE_APP_BACKEND_V2_POST_URLhttps://json-dev.excalidraw.com/api/v2/post/https://json.excalidraw.com/api/v2/post/Scene persistence endpoint
VITE_APP_LIBRARY_URLhttps://libraries.excalidraw.comhttps://libraries.excalidraw.comPublic library frontend
VITE_APP_LIBRARY_BACKENDhttps://us-central1-excalidraw-room-persistence.cloudfunctions.net/libraries(same)Library API endpoint
VITE_APP_WS_SERVER_URLhttp://localhost:3002https://oss-collab.excalidraw.comWebSocket server for collaboration
VITE_APP_AI_BACKENDhttp://localhost:3015https://oss-ai.excalidraw.comAI feature backend

Sources: .env.development3-15 .env.production3-15

Excalidraw Plus Integration

These variables configure integration with the Excalidraw Plus premium service.

VariableDevelopment ValueProduction ValuePurpose
VITE_APP_PLUS_LPhttps://plus.excalidraw.comhttps://plus.excalidraw.comPlus landing page
VITE_APP_PLUS_APPhttp://localhost:3000https://app.excalidraw.comPlus application URL
VITE_APP_PLUS_EXPORT_PUBLIC_KEY(RSA public key)(RSA public key)Public key for export encryption

Sources: .env.development12-52 .env.production9-27

Firebase Configuration

Firebase configuration is provided as a JSON string containing the Firebase project credentials.

  • Development: Uses excalidraw-oss-dev project
  • Production: Uses excalidraw-room-persistence project

Sources: .env.development17 .env.production17

Development-Specific Settings

These variables control development server behavior and debugging features.

VariableDefault ValuePurpose
VITE_APP_PORT3000Development server port
VITE_APP_DEV_DISABLE_LIVE_RELOAD(empty)Disable HMR/live reload (useful for debugging Service Workers)
FAST_REFRESHfalseReact Fast Refresh setting
VITE_APP_ENABLE_ESLINTtrue (dev), false (prod)Enable ESLint in dev server
VITE_APP_ENABLE_PWAfalseEnable PWA in development mode

Sources: .env.development22-44 .env.production32-33

Debug Flags

Debug flags enable additional debugging features during development.

VariableDefault ValuePurpose
VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX(empty)Show bounding boxes for text containers
VITE_APP_COLLAPSE_OVERLAYtrue (dev), false (prod)Collapse the debug overlay by default
VITE_APP_DISABLE_PREVENT_UNLOAD(empty)Disable the "unsaved changes" dialog

Sources: .env.development34-55 .env.production30-31

Feature Flags

Feature flags control the availability of application features.

VariableDefault ValuePurpose
VITE_APP_ENABLE_TRACKINGtrue (dev), false (prod)Enable analytics tracking

Sources: .env.development25 .env.production19

TypeScript Type Definitions

The ImportMetaEnv interface in packages/excalidraw/vite-env.d.ts5-56 provides TypeScript type definitions for all environment variables, enabling type-safe access throughout the codebase.

Sources: packages/excalidraw/vite-env.d.ts5-60

Key Type Definitions

All environment variables are typed as string in the ImportMetaEnv interface. Notable type definitions include:

  • Backend URLs: VITE_APP_BACKEND_V2_GET_URL, VITE_APP_BACKEND_V2_POST_URL, VITE_APP_WS_SERVER_URL, VITE_APP_AI_BACKEND
  • Firebase: VITE_APP_FIREBASE_CONFIG (JSON string)
  • Debug flags: VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX, VITE_APP_COLLAPSE_OVERLAY
  • Build metadata: PKG_NAME, PKG_VERSION, MODE, DEV, PROD

Sources: packages/excalidraw/vite-env.d.ts6-56

Accessing Environment Variables in Code

Environment variables are accessed via import.meta.env throughout the application:

The TypeScript compiler ensures type safety by validating all environment variable accesses against the ImportMetaEnv interface.

Sources: packages/excalidraw/vite-env.d.ts58-60

Local Configuration Overrides

Developers can create .env.local or .env.development.local files to override default values without modifying tracked files. Common use cases include:

  1. Pointing to local backend services:

  2. Disabling features during debugging:

  3. Enabling debug features:

These files are gitignored and should never be committed to version control.

Sources: .env.development19-55

Environment-Specific Configuration Matrix

The following table summarizes key differences between development and production configurations:

AspectDevelopmentProductionRationale
Backend V2 URLjson-dev.excalidraw.comjson.excalidraw.comSeparate dev/prod data stores
WebSocket Serverlocalhost:3002oss-collab.excalidraw.comLocal server for development
AI Backendlocalhost:3015oss-ai.excalidraw.comLocal AI service for testing
Plus App URLlocalhost:3000app.excalidraw.comLocal dev environment
Firebase Projectexcalidraw-oss-devexcalidraw-room-persistenceSeparate dev/prod databases
TrackingtruefalseAnalytics enabled in dev for testing
ESLinttruefalseDevelopment-time linting only
Debug FlagsEnabledfalseDebugging features in development only

Sources: .env.development3-44 .env.production3-33

Mode Variable

The MODE variable explicitly identifies the environment context:

  • .env.development: MODE="development"
  • .env.production: MODE="production"

This variable is used throughout the build process and can be accessed via import.meta.env.MODE at runtime to conditionally enable environment-specific behavior.

Sources: .env.development1 .env.production1