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
Your final, deployed URL. Astro uses this to generate your sitemap and canonical URLs.
astro.config.mjs
base
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
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
Specifies the output target for builds.
static: Build a static site (prerendered HTML)server: Build for server-side rendering (SSR)
astro.config.mjs
adapter
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
Extend Astro with integrations for frameworks, features, and libraries.
astro.config.mjs
redirects
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
The project root directory. Usually provided via CLI instead of config.
srcDir
The directory where Astro reads your site source files.
astro.config.mjs
publicDir
Directory for static assets served at
/ and copied as-is to build output.astro.config.mjs
outDir
The directory where
astro build writes the final build.astro.config.mjs
cacheDir
Directory for caching build artifacts to speed up subsequent builds.
astro.config.mjs
Build Options
Configure the build output and optimization.build.format
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
Output directory for client-side CSS and JavaScript (relative to
outDir).astro.config.mjs
build.server
Output directory for server JavaScript when building to SSR (relative to
outDir).astro.config.mjs
build.assets
Directory name for Astro-generated assets (bundled JS, CSS).
astro.config.mjs
build.assetsPrefix
CDN prefix for Astro-generated asset links.
astro.config.mjs
astro.config.mjs
build.inlineStylesheets
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
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
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
Open the browser on dev server startup.
astro.config.mjs
server.headers
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
Verify that the “origin” header matches the request URL to provide CSRF protection.
astro.config.mjs
Styling Options
scopedStyleStrategy
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
Minify HTML output to reduce file size.
astro.config.mjs
Advanced Options
vite
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