The Astro Configuration and Type System manages project settings through astro.config.* files, providing type-safe validation with Zod schemas, default value injection, and runtime configuration resolution. The system coordinates configuration loading, validation, and transformation into AstroSettings objects that drive build and development workflows.
This page documents the configuration schema definition, the resolution process, and how configuration flows through CLI commands, build processes, and development servers.
The configuration system implements a multi-stage pipeline from user configuration files to validated AstroConfig objects and runtime AstroSettings.
AstroConfig and adds runtime state like renderers and clientDirectives packages/astro/src/types/astro.ts50-70Sources: packages/astro/src/core/config/schemas/base.ts93-220 packages/astro/src/core/config/schemas/defaults.ts10-112 packages/astro/src/types/public/config.ts171-220
Astro maintains distinct TypeScript interfaces for configuration at different stages of the lifecycle.
| Type | Purpose | Source |
|---|---|---|
AstroUserConfig | The raw input from astro.config.mjs. Supports partial values and relative paths. | packages/astro/src/types/public/config.ts171-220 |
AstroConfig | The fully resolved configuration. All paths are converted to URL objects. | packages/astro/src/types/public/config.ts157-163 |
AstroSettings | The internal object used by the build/dev server. Includes the config plus runtime state. | packages/astro/src/types/astro.ts50-70 |
root, srcDir, publicDir, and outDir. These are transformed from strings to URL objects during validation packages/astro/src/core/config/schemas/base.ts94-118format (file/directory), concurrency, and assetsPrefix for CDN deployments packages/astro/src/core/config/schemas/base.ts151-181host, port, and custom headers packages/astro/src/types/public/config.ts79-151locales, defaultLocale, and routing strategies packages/astro/src/core/app/types.ts154-162Sources: packages/astro/src/core/config/schemas/base.ts94-118 packages/astro/src/types/public/config.ts79-151 packages/astro/src/core/app/types.ts154-162
astro:env)Astro provides a type-safe environment variable system via the astro:env module, supporting both public and secret variables.
The astro:env system uses an EnvSchema to define expected variables and their access levels (public vs secret).
.env files and process.env, filtering them based on the provided schema packages/astro/src/env/env-loader.ts31-98client module to prevent leakage packages/astro/src/env/vite-plugin-env.ts171-213getEnv() provides access to variables, allowing adapters to override resolution (e.g., using Cloudflare Bindings) packages/astro/src/env/runtime.ts12-16Sources: packages/astro/src/env/env-loader.ts31-98 packages/astro/src/env/vite-plugin-env.ts171-213 packages/astro/src/env/runtime.ts12-16
Astro uses zod for validation but implements a custom error mapping system to provide user-friendly diagnostics.
The zodErrorMap function intercepts Zod validation errors and transforms them into AstroError objects with helpful hints.
invalid_type errors into clear "Expected X, received Y" messages packages/astro/src/core/errors/zod-error-map.ts10-45site URL) are caught during the transform phase of the schema packages/astro/src/core/config/schemas/base.ts119integrations array to flatten nested arrays and filter out falsy values before validation packages/astro/src/core/config/schemas/base.ts143-150Sources: packages/astro/src/core/errors/zod-error-map.ts10-45 packages/astro/src/core/config/schemas/base.ts143-150
Astro supports tsconfig.json path aliases. The configAliasVitePlugin ensures these aliases work across CSS imports and module resolutions.
@import and url() references in CSS files using a regex-based replacement fallback for Vite packages/astro/src/vite-plugin-config-alias/index.ts131-169compilerOptions.paths in tsconfig.json packages/astro/src/vite-plugin-config-alias/index.ts172-206During the build, the configuration is serialized into an SSRManifest. This manifest is the "single source of truth" for the production runtime.
base, trailingSlash, renderers, and routes packages/astro/src/core/app/types.ts63-148MANIFEST_REPLACE token (@@ASTRO_MANIFEST_REPLACE@@) which is replaced with the actual JSON-serialized manifest data at the end of the bundling process packages/astro/src/core/build/plugins/plugin-manifest.ts63-117Sources: packages/astro/src/vite-plugin-config-alias/index.ts131-206 packages/astro/src/core/app/types.ts63-148 packages/astro/src/core/build/plugins/plugin-manifest.ts63-117
Sources: packages/astro/src/types/public/config.ts171-220 packages/astro/src/types/astro.ts50-70 packages/astro/src/core/app/types.ts63-148 packages/astro/src/core/base-pipeline.ts64-114
Refresh this wiki
This wiki was recently refreshed. Please wait 6 days to refresh again.