astro.config.mjs file in your project root. This guide covers how to create and structure your Astro configuration file.
Creating a Configuration File
Astro projects are configured using theastro.config.mjs file (or .ts for TypeScript). This file is optional - Astro ships with sensible defaults - but you’ll likely want to add one as your project grows.
Basic Configuration
Use thedefineConfig() helper to get IntelliSense and type-safety in your config:
astro.config.mjs
The
defineConfig() helper provides TypeScript types and autocomplete in your editor, even if you’re not using TypeScript.TypeScript Configuration
You can also use TypeScript for your config file:astro.config.ts
Configuration File Locations
Astro will automatically look for a configuration file in your project root. Supported formats:astro.config.mjs(recommended)astro.config.jsastro.config.tsastro.config.mts
Custom Configuration Path
You can specify a custom config file location using the--config CLI flag:
Common Configuration Examples
Static Site (Default)
By default, Astro builds a fully static site:astro.config.mjs
Server-Side Rendering (SSR)
Enable SSR with an adapter:astro.config.mjs
With Framework Integrations
Add framework support with integrations:astro.config.mjs
With Content Integrations
Add content processing capabilities:astro.config.mjs
Configuration Categories
Astro’s configuration options are organized into several categories:Top-Level Options
Core settings like
site, base, output, and adapterBuild Options
Control build output format, directories, and optimization
Server Options
Configure the dev server port, host, and headers
Integrations
Add framework support, content processing, and more
Environment-Based Configuration
You can conditionally configure Astro based on the environment:astro.config.mjs
The config function receives an object with
command (“dev” | “build” | “preview”) and mode properties.Loading Environment Variables
You can load environment variables in your config:astro.config.mjs
Next Steps
Astro Config Reference
Explore all available configuration options
TypeScript Configuration
Set up TypeScript in your Astro project
Vite Configuration
Customize Vite settings for advanced use cases
Integrations Guide
Learn about Astro’s integration system