astro.config.mjs.
Top-Level Options
site
Your final, deployed URL. Astro uses this full URL to generate your sitemap and canonical URLs in your final build.
base
The base path to deploy to. Astro will use this path as the root for your pages and assets both in development and in production build.When using this option, all of your static asset imports and URLs should add the base as a prefix. You can access this value via
import.meta.env.BASE_URL.trailingSlash
Set the route matching behavior for trailing slashes in the dev server and on-demand rendered pages.
'ignore'- Match URLs regardless of whether a trailing ”/” exists'always'- Only match URLs that include a trailing slash (e.g: “/about/”)'never'- Only match URLs that do not include a trailing slash (e.g: “/about”)
redirects
Specify a mapping of redirects where the key is the route to match and the value is the path to redirect to.For statically-generated sites with no adapter, this produces a client redirect using a
<meta http-equiv="refresh"> tag. When using SSR or with a static adapter, status codes are supported.output
Specifies the output target for builds.
'static'- Prerender all your pages by default, outputting a completely static site'server'- Use server-side rendering (SSR) for all pages by default
adapter
Deploy to your favorite server, serverless, or edge host with build adapters. Import one of our first-party adapters for Cloudflare, Netlify, Node.js, Vercel, and more to enable SSR.
integrations
Extend Astro with custom integrations. Integrations are your one-stop-shop for adding framework support (like Solid.js), new features (like sitemaps), and new libraries.
root
Set the project root. The project root is the directory where your Astro project (and all If you provide a relative path, Astro will resolve it against your current working directory.
src, public and package.json files) live.srcDir
Set the directory that Astro will read your site from.
publicDir
Set the directory for your static assets. Files in this directory are served at
/ during dev and copied to your build directory during build.outDir
Set the directory that
astro build writes your final build to.cacheDir
Set the directory for caching build artifacts. Files in this directory will be used in subsequent builds to speed up the build time.
compressHTML
Minify your HTML output and reduce the size of your HTML files. By default, Astro removes whitespace from your HTML in a lossless manner.
scopedStyleStrategy
Specify the strategy used for scoping styles within Astro components.
'where'- Use:whereselectors, causing no specificity increase'class'- Use class-based selectors, causing a +1 specificity increase'attribute'- Usedata-attributes, causing a +1 specificity increase
vite
Pass additional configuration options to Vite. Useful when Astro doesn’t support some advanced configuration that you may need.
Build Options
build.format
Control the output file format of each page.
'file': Generate an HTML file named for each page route (e.g./about.html)'directory': Generate a directory with a nestedindex.htmlfile for each page (e.g./about/index.html)'preserve': Generate HTML files exactly as they appear in your source folder
build.client
Controls the output directory of your client-side CSS and JavaScript when building with SSR. This value is relative to the
outDir.build.server
Controls the output directory of server JavaScript when building to SSR. This value is relative to the
outDir.build.assets
Specifies the directory in the build output where Astro-generated assets (bundled JS and CSS) should live.
build.assetsPrefix
Specifies the prefix for Astro-generated asset links. Use this if assets are served from a different domain than the current site.You can also pass an object to specify different domains for each file type:
build.serverEntry
Specifies the file name of the server entrypoint when building to SSR. This entrypoint is usually dependent on which host you are deploying to.
build.redirects
Specifies whether redirects will be output to HTML during the build. This option only applies to
output: 'static' mode.build.inlineStylesheets
Control whether project styles are sent to the browser in a separate css file or inlined into
<style> tags.'always'- project styles are inlined into<style>tags'auto'- only stylesheets smaller than 4kb are inlined'never'- project styles are sent in external stylesheets
build.concurrency
The number of pages to build in parallel. In most cases, you should not change the default value of 1.
Server Options
server.host
Set which network IP addresses the server should listen on (i.e. non-localhost IPs).
false- do not expose on a network IP addresstrue- listen on all addresses, including LAN and public addresses[custom-address]- expose on a network IP address at[custom-address]
server.port
Set which port the server should listen on. If the given port is already in use, Astro will automatically try the next available port.
server.allowedHosts
A list of hostnames that Astro is allowed to respond to. When the value is set to
true, any hostname is allowed.server.open
Controls whether the dev server should open in your browser window on startup.
server.headers
Set custom HTTP response headers to be sent in
astro dev and astro preview.Image Options
image.service
Set which image service is used for Astro’s assets support.
image.endpoint
Set the endpoint to use for image optimization in dev and SSR.
image.domains
Defines a list of permitted image source domains for remote image optimization. No other remote images will be optimized by Astro.
image.remotePatterns
Defines a list of permitted image source URL patterns for remote image optimization.You can use wildcards:
hostname: Start with**to allow all subdomains, or*for one levelpathname: End with/**to allow all sub-routes, or/*for one level
image.layout
The default layout type for responsive images. Can be overridden by the
layout prop on the image component.constrained- The image will scale to fit the container, maintaining aspect ratiofixed- The image will maintain its original dimensionsfull-width- The image will scale to fit the container
image.responsiveStyles
Whether to automatically add global styles for responsive images. Enable this unless you are styling images yourself.
Markdown Options
markdown.syntaxHighlight
Which syntax highlighter to use for Markdown code blocks.
'shiki'- use the Shiki highlighter'prism'- use the Prism highlighterfalse- do not apply syntax highlighting
markdown.shikiConfig
Configure Shiki syntax highlighter options.
markdown.remarkPlugins
Pass remark plugins to customize how your Markdown is built.
markdown.rehypePlugins
Pass rehype plugins to customize how your Markdown’s output HTML is processed.
markdown.gfm
Astro uses GitHub-flavored Markdown by default. To disable this, set the
gfm flag to false.markdown.smartypants
Astro uses the SmartyPants formatter by default. To disable this, set the
smartypants flag to false.Security Options
security.checkOrigin
Performs a check that the “origin” header matches the URL sent by each request. This provides Cross-Site Request Forgery (CSRF) protection for SSR pages.
security.actionBodySizeLimit
Sets the maximum size in bytes allowed for action request bodies. Default is 1 MB.
Session Options
session.driver
The driver to use for session storage. Some adapters automatically configure a default driver.
session.ttl
An optional default time-to-live expiration period for session values, in seconds.
i18n Options
i18n.locales
A list of all locales supported by the website. This is a required field.You can also map to shared paths:
i18n.defaultLocale
The default locale of your website/application. This is a required field.
i18n.fallback
The fallback strategy when navigating to pages that do not exist.
i18n.routing
Controls the routing strategy to determine your site URLs.
Dev Toolbar Options
devToolbar.enabled
Whether to enable the Astro Dev Toolbar. This toolbar allows you to inspect your page islands, see helpful audits on performance and accessibility, and more.
devToolbar.placement
The default placement of the Astro Dev Toolbar on the screen.
Prefetch Options
prefetch.prefetchAll
Enable prefetching for all links, including those without the
data-astro-prefetch attribute.prefetch.defaultStrategy
The default prefetch strategy when the
data-astro-prefetch attribute is set with no value.'tap'- Prefetch just before you click on the link'hover'- Prefetch when you hover over or focus on the link'viewport'- Prefetch as the links enter the viewport'load'- Prefetch all links on the page after the page is loaded