astro.config.mjs. For an introduction to Astro configuration, see the Configuration Overview.
Top-Level Options
These options configure fundamental aspects of your Astro project.site
string
Your final, deployed URL. Astro uses this to generate your sitemap and canonical URLs.
astro.config.mjs
base
string
default:"/"
The base path to deploy to. Astro uses this path as the root for pages and assets in development and production.
astro.config.mjs
base, all asset imports and URLs should include the base prefix. Access it via import.meta.env.BASE_URL:
src/pages/index.astro
trailingSlash
'always' | 'never' | 'ignore'
default:"'ignore'"
Control URL trailing slash behavior in the dev server and on-demand rendered pages.
ignore: Match URLs regardless of trailing slashalways: Only match URLs with a trailing slash (e.g.,/about/)never: Only match URLs without a trailing slash (e.g.,/about)
astro.config.mjs
output
'static' | 'server'
default:"'static'"
Specifies the output target for builds.
static: Build a static site (prerendered HTML)server: Build for server-side rendering (SSR)
astro.config.mjs
adapter
AstroIntegration
Deploy adapter for SSR. Required when
output: 'server'.astro.config.mjs
Node.js
Deploy to Node.js servers
Vercel
Deploy to Vercel
Netlify
Deploy to Netlify
Cloudflare
Deploy to Cloudflare
integrations
AstroIntegration[]
Extend Astro with integrations for frameworks, features, and libraries.
astro.config.mjs
redirects
Record<string, RedirectConfig>
default:"{}"
Define URL redirects. Keys are routes to match, values are destinations.
astro.config.mjs
Static sites use a
<meta http-equiv="refresh"> tag. SSR and adapter-enabled static sites support status codes.Directory Options
Customize project directory structure.root
string
default:"'.'"
The project root directory. Usually provided via CLI instead of config.
srcDir
string
default:"'./src'"
The directory where Astro reads your site source files.
astro.config.mjs
publicDir
string
default:"'./public'"
Directory for static assets served at
/ and copied as-is to build output.astro.config.mjs
outDir
string
default:"'./dist'"
The directory where
astro build writes the final build.astro.config.mjs
cacheDir
string
default:"'./node_modules/.astro'"
Directory for caching build artifacts to speed up subsequent builds.
astro.config.mjs
Build Options
Configure the build output and optimization.build.format
'file' | 'directory' | 'preserve'
default:"'directory'"
Control the output file format for each page.
file: Generateabout.htmlfor each pagedirectory: Generateabout/index.htmlfor each pagepreserve: Keep the same structure as source files
astro.config.mjs
The
format affects Astro.url.pathname during build. Use with trailingSlash for consistent URLs.build.client
string
default:"'./client'"
Output directory for client-side CSS and JavaScript (relative to
outDir).astro.config.mjs
build.server
string
default:"'./server'"
Output directory for server JavaScript when building to SSR (relative to
outDir).astro.config.mjs
build.assets
string
default:"'_astro'"
Directory name for Astro-generated assets (bundled JS, CSS).
astro.config.mjs
build.assetsPrefix
string | Record<string, string>
CDN prefix for Astro-generated asset links.
astro.config.mjs
astro.config.mjs
build.inlineStylesheets
'always' | 'auto' | 'never'
default:"'auto'"
Control whether styles are inlined or in separate CSS files.
always: Inline all styles in<style>tagsauto: Inline only stylesheets smaller than 4kbnever: Send all styles in external files
astro.config.mjs
Server Options
Customize the Astro dev server forastro dev and astro preview.
server.port
number
default:"4321"
The port the dev server listens on.
astro.config.mjs
If the port is in use, Astro automatically tries the next available port.
server.host
string | boolean
default:"false"
Set which network IP addresses the server listens on.
false: Don’t expose on network IPtrue: Listen on all addresses (LAN and public)[custom-address]: Expose on specific IP address
astro.config.mjs
server.open
string | boolean
default:"false"
Open the browser on dev server startup.
astro.config.mjs
server.headers
OutgoingHttpHeaders
default:"{}"
Custom HTTP response headers for
astro dev and astro preview.astro.config.mjs
Dynamic Server Configuration
You can provide a function to configure the server based on the command:astro.config.mjs
Security Options
Enable security features for SSR pages.security.checkOrigin
boolean
default:"true"
Verify that the “origin” header matches the request URL to provide CSRF protection.
astro.config.mjs
Styling Options
scopedStyleStrategy
'where' | 'class' | 'attribute'
default:"'attribute'"
Strategy for scoping styles within Astro components.
where: Use:whereselectors (no specificity increase)class: Use class-based selectors (+1 specificity)attribute: Usedata-attributes (+1 specificity)
astro.config.mjs
compressHTML
boolean
default:"true"
Minify HTML output to reduce file size.
astro.config.mjs
Advanced Options
vite
ViteUserConfig
Pass additional configuration to Vite. See Vite Configuration for details.
astro.config.mjs
Next Steps
TypeScript Config
Configure TypeScript for your project
Vite Config
Advanced Vite configuration options
Environment Variables
Use environment variables in your project
Integrations
Extend Astro with integrations