Astro configuration
Theastro.config.mjs file controls how Astro builds and serves your site. This minimal starter uses a basic configuration, but you can extend it with numerous options.
Basic configuration
The default configuration uses Astro’s standard settings:astro.config.mjs
Common configuration options
While the starter template uses default settings, you can customize your project by adding configuration options:The URL where your site will be deployed. Required for generating sitemaps and canonical URLs.
The base path where your site will be deployed. Useful when deploying to a subdirectory.
The directory where Astro writes your final build output.
The directory for static assets that are served as-is.
Controls whether route URLs should have trailing slashes. Options:
'always', 'never', or 'ignore'.Server configuration
Configure the development server behavior:The port to run the development server on.
Set which network IP addresses the server should listen on. Set to
true to listen on all addresses.Build configuration
Customize the build output:Controls the file format of each page’s build output. Options:
'file' or 'directory'.The minimal starter template uses Astro’s default configuration. You can add any of these options as your project grows.
TypeScript configuration
Thetsconfig.json file configures TypeScript’s behavior in your project. This starter uses Astro’s strict preset for maximum type safety.
Base configuration
tsconfig.json
Configuration breakdown
Inherits settings from Astro’s strict TypeScript configuration. This provides recommended TypeScript settings optimized for Astro projects.Available presets:
astro/tsconfigs/base- Basic TypeScript supportastro/tsconfigs/strict- Strict type checking (recommended)astro/tsconfigs/strictest- Maximum type safety
Specifies which files TypeScript should process:
.astro/types.d.ts- Auto-generated type definitions**/*- All files in the project
Excludes the
dist directory (build output) from TypeScript processing.Customizing TypeScript settings
You can add compiler options to override or extend the base configuration:Path aliases defined in
tsconfig.json must also be configured in astro.config.mjs using the vite.resolve.alias option for runtime resolution.Environment-specific configuration
You can use environment variables to configure different settings for development and production:astro.config.mjs
Configuration best practices
Use TypeScript for configuration
Use TypeScript for configuration
The
astro.config.mjs file includes // @ts-check at the top to enable TypeScript checking in JavaScript files. This catches configuration errors before runtime.Start minimal, add as needed
Start minimal, add as needed
The starter template provides a minimal configuration. Add options only when you need them to keep your configuration maintainable.
Leverage presets
Leverage presets
Use Astro’s TypeScript presets (
strict, strictest) rather than configuring all compiler options manually. This ensures compatibility with Astro’s build system.Document custom settings
Document custom settings
If you add non-standard configuration options, document why they’re needed for future maintainers.
Next steps
- Explore available npm scripts for development and deployment
- Learn about Astro’s full configuration API
- Review TypeScript configuration options