UNPKG

astro

Version:

Astro is a modern site builder with web best practices, performance, and DX front-of-mind.

1,320 lines (1,319 loc) 87.5 kB
import type { OutgoingHttpHeaders } from 'node:http'; import type { RemotePattern } from '@astrojs/internal-helpers/remote'; import type { RehypePlugins, RemarkPlugins, RemarkRehype, ShikiConfig, SyntaxHighlightConfigType } from '@astrojs/markdown-remark'; import type { BuiltinDriverName, BuiltinDriverOptions, Driver, Storage } from 'unstorage'; import type { UserConfig as OriginalViteUserConfig, SSROptions as ViteSSROptions } from 'vite'; import type { AstroFontProvider, FontFamily } from '../../assets/fonts/types.js'; import type { ImageFit, ImageLayout } from '../../assets/types.js'; import type { AssetsPrefix } from '../../core/app/types.js'; import type { AstroConfigType } from '../../core/config/schemas/index.js'; import type { REDIRECT_STATUS_CODES } from '../../core/constants.js'; import type { AstroCookieSetOptions } from '../../core/cookies/cookies.js'; import type { LoggerLevel } from '../../core/logger/core.js'; import type { EnvSchema } from '../../env/schema.js'; import type { AstroIntegration } from './integrations.js'; export type Locales = (string | { codes: [string, ...string[]]; path: string; })[]; export type { AstroFontProvider as FontProvider }; type NormalizeLocales<T extends Locales> = { [K in keyof T]: T[K] extends string ? T[K] : T[K] extends { codes: Array<string>; } ? T[K]['codes'][number] : never; }[number]; export interface ImageServiceConfig<T extends Record<string, any> = Record<string, any>> { entrypoint: 'astro/assets/services/sharp' | (string & {}); config?: T; } export type RuntimeMode = 'development' | 'production'; export type ValidRedirectStatus = (typeof REDIRECT_STATUS_CODES)[number]; export type RedirectConfig = string | { status: ValidRedirectStatus; destination: string; }; export type ServerConfig = { /** * @name server.host * @type {string | boolean} * @default `false` * @version 0.24.0 * @description * Set which network IP addresses the dev server should listen on (i.e. non-localhost IPs). * - `false` - do not expose on a network IP address * - `true` - listen on all addresses, including LAN and public addresses * - `[custom-address]` - expose on a network IP address at `[custom-address]` */ host?: string | boolean; /** * @name server.port * @type {number} * @default `4321` * @description * Set which port the dev server should listen on. * * If the given port is already in use, Astro will automatically try the next available port. */ port?: number; /** * @name server.allowedHosts * @type {string[] | true} * @default `[]` * @version 5.4.0 * @description * * A list of hostnames that Astro is allowed to respond to. When the value is set to `true`, any * hostname is allowed. * * ```js * { * server: { * allowedHosts: ['staging.example.com', 'qa.example.com'] * } * } * ``` */ allowedHosts?: string[] | true; /** * @name server.headers * @typeraw {OutgoingHttpHeaders} * @default `{}` * @version 1.7.0 * @description * Set custom HTTP response headers to be sent in `astro dev` and `astro preview`. */ headers?: OutgoingHttpHeaders; /** * @name server.open * @type {string | boolean} * @default `false` * @version 4.1.0 * @description * Controls whether the dev server should open in your browser window on startup. * * Pass a full URL string (e.g. "http://example.com") or a pathname (e.g. "/about") to specify the URL to open. * * ```js * { * server: { open: "/about" } * } * ``` */ open?: string | boolean; }; export type SessionDriverName = BuiltinDriverName | 'custom' | 'test'; interface CommonSessionConfig { /** * Configures the session cookie. If set to a string, it will be used as the cookie name. * Alternatively, you can pass an object with additional options. */ cookie?: string | (Omit<AstroCookieSetOptions, 'httpOnly' | 'expires' | 'encode'> & { name?: string; }); /** * Default session duration in seconds. If not set, the session will be stored until deleted, or until the cookie expires. */ ttl?: number; } interface BuiltinSessionConfig<TDriver extends keyof BuiltinDriverOptions> extends CommonSessionConfig { driver: TDriver; options?: BuiltinDriverOptions[TDriver]; } interface CustomSessionConfig extends CommonSessionConfig { /** Entrypoint for a custom session driver */ driver: string; options?: Record<string, unknown>; } interface TestSessionConfig extends CommonSessionConfig { driver: 'test'; options: { mockStorage: Storage; }; } export type SessionConfig<TDriver extends SessionDriverName> = TDriver extends keyof BuiltinDriverOptions ? BuiltinSessionConfig<TDriver> : TDriver extends 'test' ? TestSessionConfig : CustomSessionConfig; export type ResolvedSessionConfig<TDriver extends SessionDriverName> = SessionConfig<TDriver> & { driverModule?: () => Promise<{ default: () => Driver; }>; }; export interface ViteUserConfig extends OriginalViteUserConfig { ssr?: ViteSSROptions; } /** * Astro User Config * Docs: https://docs.astro.build/reference/configuration-reference/ * * Generics do not follow semver and may change at any time. */ export interface AstroUserConfig<TLocales extends Locales = never, TSession extends SessionDriverName = never, TFontFamilies extends FontFamily[] = never> { /** * @docs * @kind heading * @name Top-Level Options */ /** * @docs * @name site * @type {string} * @description * Your final, deployed URL. Astro uses this full URL to generate your sitemap and canonical URLs in your final build. It is strongly recommended that you set this configuration to get the most out of Astro. * * ```js * { * site: 'https://www.my-site.dev' * } * ``` */ site?: string; /** * @docs * @name base * @type {string} * @description * 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. * * In the example below, `astro dev` will start your server at `/docs`. * * ```js * { * base: '/docs' * } * ``` * * 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`. * * The value of `import.meta.env.BASE_URL` will be determined by your `trailingSlash` config, no matter what value you have set for `base`. * * A trailing slash is always included if `trailingSlash: "always"` is set. If `trailingSlash: "never"` is set, `BASE_URL` will not include a trailing slash, even if `base` includes one. * * Additionally, Astro will internally manipulate the configured value of `config.base` before making it available to integrations. The value of `config.base` as read by integrations will also be determined by your `trailingSlash` configuration in the same way. * * In the example below, the values of `import.meta.env.BASE_URL` and `config.base` when processed will both be `/docs`: * ```js * { * base: '/docs/', * trailingSlash: "never" * } * ``` * * In the example below, the values of `import.meta.env.BASE_URL` and `config.base` when processed will both be `/docs/`: * * ```js * { * base: '/docs', * trailingSlash: "always" * } * ``` */ base?: string; /** * @docs * @name trailingSlash * @type {('always' | 'never' | 'ignore')} * @default `'ignore'` * @see build.format * @description * * Set the route matching behavior for trailing slashes in the dev server and on-demand rendered pages. Choose from the following options: * - `'ignore'` - Match URLs regardless of whether a trailing "/" exists. Requests for "/about" and "/about/" will both match the same route. * - `'always'` - Only match URLs that include a trailing slash (e.g: "/about/"). In production, requests for on-demand rendered URLs without a trailing slash will be redirected to the correct URL for your convenience. However, in development, they will display a warning page reminding you that you have `always` configured. * - `'never'` - Only match URLs that do not include a trailing slash (e.g: "/about"). In production, requests for on-demand rendered URLs with a trailing slash will be redirected to the correct URL for your convenience. However, in development, they will display a warning page reminding you that you have `never` configured. * * When redirects occur in production for GET requests, the redirect will be a 301 (permanent) redirect. For all other request methods, it will be a 308 (permanent, and preserve the request method) redirect. * * Trailing slashes on prerendered pages are handled by the hosting platform, and may not respect your chosen configuration. * See your hosting platform's documentation for more information. You cannot use Astro [redirects](#redirects) for this use case at this point. * * ```js * { * // Example: Require a trailing slash during development * trailingSlash: 'always' * } * ``` */ trailingSlash?: 'always' | 'never' | 'ignore'; /** * @docs * @name redirects * @type {Record<string, RedirectConfig>} * @default `{}` * @version 2.9.0 * @description Specify a mapping of redirects where the key is the route to match * and the value is the path to redirect to. * * You can redirect both static and dynamic routes, but only to the same kind of route. * For example, you cannot have a `'/article': '/blog/[...slug]'` redirect. * * * ```js * export default defineConfig({ * redirects: { * '/old': '/new', * '/blog/[...slug]': '/articles/[...slug]', * '/about': 'https://example.com/about', * '/news': { * status: 302, * destination: 'https://example.com/news' * }, * // '/product1/', '/product1' // Note, this is not supported * } * }) * ``` * * * For statically-generated sites with no adapter installed, this will produce a client redirect using a [`<meta http-equiv="refresh">` tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta#http-equiv) and does not support status codes. * * When using SSR or with a static adapter in `output: static` * mode, status codes are supported. * Astro will serve redirected GET requests with a status of `301` * and use a status of `308` for any other request method. * * You can customize the [redirection status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages) using an object in the redirect config: * * ```js * export default defineConfig({ * redirects: { * '/other': { * status: 302, * destination: '/place', * }, * } * }) * * * ``` */ redirects?: Record<string, RedirectConfig>; /** * @docs * @name output * @type {('static' | 'server')} * @default `'static'` * @see adapter * @description * * Specifies the output target for builds. * * - `'static'` - Prerender all your pages by default, outputting a completely static site if none of your pages opt out of prerendering. * - `'server'` - Use server-side rendering (SSR) for all pages by default, always outputting a server-rendered site. * * ```js * import { defineConfig } from 'astro/config'; * * export default defineConfig({ * output: 'static' * }) * ``` */ output?: 'static' | 'server'; /** * @docs * @name adapter * @typeraw {AstroIntegration} * @see output * @description * * Deploy to your favorite server, serverless, or edge host with build adapters. Import one of our first-party adapters ([Cloudflare](/en/guides/integrations-guide/cloudflare/), [Netlify](/en/guides/integrations-guide/netlify/), [Node.js](/en/guides/integrations-guide/node/), [Vercel](/en/guides/integrations-guide/vercel/)) or explore [community adapters](https://astro.build/integrations/2/?search=&categories%5B%5D=adapters) to enable on-demand rendering in your Astro project. * * See our [on-demand rendering guide](/en/guides/on-demand-rendering/) for more on Astro's server rendering options. * * ```js * import netlify from '@astrojs/netlify'; * { * // Example: Build for Netlify serverless deployment * adapter: netlify(), * } * ``` */ adapter?: AstroIntegration; /** * @docs * @name integrations * @typeraw {AstroIntegration[]} * @description * * 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 (like Partytown). * * Read our [Integrations Guide](https://docs.astro.build/en/guides/integrations-guide/) for help getting started with Astro Integrations. * * ```js * import react from '@astrojs/react'; * import mdx from '@astrojs/mdx'; * { * // Example: Add React + MDX support to Astro * integrations: [react(), mdx()] * } * ``` */ integrations?: Array<AstroIntegration | (AstroIntegration | false | undefined | null)[] | false | undefined | null>; /** * @docs * @name root * @cli --root * @type {string} * @default `"."` (current working directory) * @summary Set the project root. The project root is the directory where your Astro project (and all `src`, `public` and `package.json` files) live. * @description You should only provide this option if you run the `astro` CLI commands in a directory other than the project root directory. Usually, this option is provided via the CLI instead of the Astro config file, since Astro needs to know your project root before it can locate your config file. * * If you provide a relative path (ex: `--root: './my-project'`) Astro will resolve it against your current working directory. * * #### Examples * * ```js * { * root: './my-project-directory' * } * ``` * ```bash * $ astro build --root ./my-project-directory * ``` */ root?: string; /** * @docs * @name srcDir * @type {string} * @default `"./src"` * @description Set the directory that Astro will read your site from. * * The value can be either an absolute file system path or a path relative to the project root. * * ```js * { * srcDir: './www' * } * ``` */ srcDir?: string; /** * @docs * @name publicDir * @type {string} * @default `"./public"` * @description * Set the directory for your static assets. Files in this directory are served at `/` during dev and copied to your build directory during build. These files are always served or copied as-is, without transform or bundling. * * The value can be either an absolute file system path or a path relative to the project root. * * ```js * { * publicDir: './my-custom-publicDir-directory' * } * ``` */ publicDir?: string; /** * @docs * @name outDir * @type {string} * @default `"./dist"` * @see build.server * @description Set the directory that `astro build` writes your final build to. * * The value can be either an absolute file system path or a path relative to the project root. * * ```js * { * outDir: './my-custom-build-directory' * } * ``` */ outDir?: string; /** * @docs * @name cacheDir * @type {string} * @default `"./node_modules/.astro"` * @description Set the directory for caching build artifacts. Files in this directory will be used in subsequent builds to speed up the build time. * * The value can be either an absolute file system path or a path relative to the project root. * * ```js * { * cacheDir: './my-custom-cache-directory' * } * ``` */ cacheDir?: string; /** * @docs * @name compressHTML * @type {boolean} * @default `true` * @description * * This is an option to minify your HTML output and reduce the size of your HTML files. * * By default, Astro removes whitespace from your HTML, including line breaks, from `.astro` components in a lossless manner. * Some whitespace may be kept as needed to preserve the visual rendering of your HTML. This occurs both in development mode and in the final build. * * To disable HTML compression, set `compressHTML` to false. * * ```js * { * compressHTML: false * } * ``` */ compressHTML?: boolean; /** * @docs * @name scopedStyleStrategy * @type {('where' | 'class' | 'attribute')} * @default `'attribute'` * @version 2.4 * @description * * Specify the strategy used for scoping styles within Astro components. Choose from: * - `'where'` - Use `:where` selectors, causing no specificity increase. * - `'class'` - Use class-based selectors, causing a +1 specificity increase. * - `'attribute'` - Use `data-` attributes, causing a +1 specificity increase. * * Using `'class'` is helpful when you want to ensure that element selectors within an Astro component override global style defaults (e.g. from a global stylesheet). * Using `'where'` gives you more control over specificity, but requires that you use higher-specificity selectors, layers, and other tools to control which selectors are applied. * Using `'attribute'` is useful when you are manipulating the `class` attribute of elements and need to avoid conflicts between your own styling logic and Astro's application of styles. */ scopedStyleStrategy?: 'where' | 'class' | 'attribute'; /** * @docs * @name security * @type {Record<"checkOrigin", boolean> | undefined} * @default `{checkOrigin: true}` * @version 4.9.0 * @description * * Enables security measures for an Astro website. * * These features only exist for pages rendered on demand (SSR) using `server` mode or pages that opt out of prerendering in `static` mode. * * By default, Astro will automatically check that the “origin” header * matches the URL sent by each request in on-demand rendered pages. You can * disable this behavior by setting `checkOrigin` to `false`: * * ```js * // astro.config.mjs * export default defineConfig({ * output: "server", * security: { * checkOrigin: false * } * }) * ``` */ security?: { /** * @docs * @name security.checkOrigin * @kind h4 * @type {boolean} * @default `true` * @version 4.9.0 * @description * * Performs a check that the "origin" header, automatically passed by all modern browsers, matches the URL sent by each `Request`. This is used to provide Cross-Site Request Forgery (CSRF) protection. * * The "origin" check is executed only for pages rendered on demand, and only for the requests `POST`, `PATCH`, `DELETE` and `PUT` with * one of the following `content-type` headers: `'application/x-www-form-urlencoded'`, `'multipart/form-data'`, `'text/plain'`. * * If the "origin" header doesn't match the `pathname` of the request, Astro will return a 403 status code and will not render the page. */ checkOrigin?: boolean; }; /** * @docs * @name vite * @typeraw {ViteUserConfig} * @description * * Pass additional configuration options to Vite. Useful when Astro doesn't support some advanced configuration that you may need. * * View the full `vite` configuration object documentation on [vite.dev](https://vite.dev/config/). * * #### Examples * * ```js * { * vite: { * ssr: { * // Example: Force a broken package to skip SSR processing, if needed * external: ['broken-npm-package'], * } * } * } * ``` * * ```js * { * vite: { * // Example: Add custom vite plugins directly to your Astro project * plugins: [myPlugin()], * } * } * ``` */ vite?: ViteUserConfig; /** * @docs * @kind heading * @name Build Options */ build?: { /** * @docs * @name build.format * @typeraw {('file' | 'directory' | 'preserve')} * @default `'directory'` * @description * Control the output file format of each page. This value may be set by an adapter for you. * - `'file'`: Astro will generate an HTML file named for each page route. (e.g. `src/pages/about.astro` and `src/pages/about/index.astro` both build the file `/about.html`) * - `'directory'`: Astro will generate a directory with a nested `index.html` file for each page. (e.g. `src/pages/about.astro` and `src/pages/about/index.astro` both build the file `/about/index.html`) * - `'preserve'`: Astro will generate HTML files exactly as they appear in your source folder. (e.g. `src/pages/about.astro` builds `/about.html` and `src/pages/about/index.astro` builds the file `/about/index.html`) * * ```js * { * build: { * // Example: Generate `page.html` instead of `page/index.html` during build. * format: 'file' * } * } * ``` * * * * #### Effect on Astro.url * Setting `build.format` controls what `Astro.url` is set to during the build. When it is: * - `directory` - The `Astro.url.pathname` will include a trailing slash to mimic folder behavior. (e.g. `/foo/`) * - `file` - The `Astro.url.pathname` will include `.html`. (e.g. `/foo.html`) * * This means that when you create relative URLs using `new URL('./relative', Astro.url)`, you will get consistent behavior between dev and build. * * To prevent inconsistencies with trailing slash behaviour in dev, you can restrict the [`trailingSlash` option](#trailingslash) to `'always'` or `'never'` depending on your build format: * - `directory` - Set `trailingSlash: 'always'` * - `file` - Set `trailingSlash: 'never'` */ format?: 'file' | 'directory' | 'preserve'; /** * @docs * @name build.client * @type {string} * @default `'./client'` * @description * Controls the output directory of your client-side CSS and JavaScript when building a website with server-rendered pages. * `outDir` controls where the code is built to. * * This value is relative to the `outDir`. * * ```js * { * output: 'server', * build: { * client: './client' * } * } * ``` */ client?: string; /** * @docs * @name build.server * @type {string} * @default `'./server'` * @description * Controls the output directory of server JavaScript when building to SSR. * * This value is relative to the `outDir`. * * ```js * { * build: { * server: './server' * } * } * ``` */ server?: string; /** * @docs * @name build.assets * @type {string} * @default `'_astro'` * @see outDir * @version 2.0.0 * @description * Specifies the directory in the build output where Astro-generated assets (bundled JS and CSS for example) should live. * * ```js * { * build: { * assets: '_custom' * } * } * ``` */ assets?: string; /** * @docs * @name build.assetsPrefix * @type {string | Record<string, string>} * @default `undefined` * @version 2.2.0 * @description * Specifies the prefix for Astro-generated asset links. This can be used if assets are served from a different domain than the current site. * * This requires uploading the assets in your local `./dist/_astro` folder to a corresponding `/_astro/` folder on the remote domain. * To rename the `_astro` path, specify a new directory in `build.assets`. * * To fetch all assets uploaded to the same domain (e.g. `https://cdn.example.com/_astro/...`), set `assetsPrefix` to the root domain as a string (regardless of your `base` configuration): * * ```js * { * build: { * assetsPrefix: 'https://cdn.example.com' * } * } * ``` * * **Added in:** `astro@4.5.0` * * You can also pass an object to `assetsPrefix` to specify a different domain for each file type. * In this case, a `fallback` property is required and will be used by default for any other files. * * ```js * { * build: { * assetsPrefix: { * 'js': 'https://js.cdn.example.com', * 'mjs': 'https://js.cdn.example.com', * 'css': 'https://css.cdn.example.com', * 'fallback': 'https://cdn.example.com' * } * } * } * ``` * */ assetsPrefix?: AssetsPrefix; /** * @docs * @name build.serverEntry * @type {string} * @default `'entry.mjs'` * @description * Specifies the file name of the server entrypoint when building to SSR. * This entrypoint is usually dependent on which host you are deploying to and * will be set by your adapter for you. * * Note that it is recommended that this file ends with `.mjs` so that the runtime * detects that the file is a JavaScript module. * * ```js * { * build: { * serverEntry: 'main.mjs' * } * } * ``` */ serverEntry?: string; /** * @docs * @name build.redirects * @type {boolean} * @default `true` * @version 2.6.0 * @description * Specifies whether redirects will be output to HTML during the build. * This option only applies to `output: 'static'` mode; in SSR redirects * are treated the same as all responses. * * This option is mostly meant to be used by adapters that have special * configuration files for redirects and do not need/want HTML based redirects. * * ```js * { * build: { * redirects: false * } * } * ``` */ redirects?: boolean; /** * @docs * @name build.inlineStylesheets * @type {('always' | 'auto' | 'never')} * @default `auto` * @version 2.6.0 * @description * Control whether project styles are sent to the browser in a separate css file or inlined into `<style>` tags. Choose from the following options: * - `'always'` - project styles are inlined into `<style>` tags * - `'auto'` - only stylesheets smaller than `ViteConfig.build.assetsInlineLimit` (default: 4kb) are inlined. Otherwise, project styles are sent in external stylesheets. * - `'never'` - project styles are sent in external stylesheets * * ```js * { * build: { * inlineStylesheets: `never`, * }, * } * ``` */ inlineStylesheets?: 'always' | 'auto' | 'never'; /** * @docs * @name build.concurrency * @type { number } * @default `1` * @version 4.16.0 * @description * The number of pages to build in parallel. * * **In most cases, you should not change the default value of `1`.** * * Use this option only when other attempts to reduce the overall rendering time (e.g. batch or cache long running tasks like fetch calls or data access) are not possible or are insufficient. * If the number is set too high, page rendering may slow down due to insufficient memory resources and because JS is single-threaded. * * ```js * { * build: { * concurrency: 2 * } * } * ``` * * :::caution[Breaking changes possible] * This feature is stable and is not considered experimental. However, this feature is only intended to address difficult performance issues, and breaking changes may occur in a [minor release](https://docs.astro.build/en/upgrade-astro/#semantic-versioning) to keep this option as performant as possible. Please check the [Astro CHANGELOG](https://github.com/withastro/astro/blob/refs/heads/next/packages/astro/CHANGELOG.md) for every minor release if you are using this feature. * ::: */ concurrency?: number; }; /** * @docs * @kind heading * @name Server Options * @description * * Customize the Astro dev server, used by both `astro dev` and `astro preview`. * * ```js * { * server: { port: 1234, host: true} * } * ``` * * To set different configuration based on the command run ("dev", "preview") a function can also be passed to this configuration option. * * ```js * { * // Example: Use the function syntax to customize based on command * server: ({ command }) => ({ port: command === 'dev' ? 4321 : 4000 }) * } * ``` */ /** * @docs * @name server.host * @type {string | boolean} * @default `false` * @version 0.24.0 * @description * Set which network IP addresses the server should listen on (i.e. non-localhost IPs). * - `false` - do not expose on a network IP address * - `true` - listen on all addresses, including LAN and public addresses * - `[custom-address]` - expose on a network IP address at `[custom-address]` (ex: `192.168.0.1`) */ /** * @docs * @name server.port * @type {number} * @default `4321` * @description * Set which port the server should listen on. * * If the given port is already in use, Astro will automatically try the next available port. * * ```js * { * server: { port: 8080 } * } * ``` */ /** * @docs * @name server.allowedHosts * @type {string[] | true} * @default `[]` * @version 5.4.0 * @description * * A list of hostnames that Astro is allowed to respond to. When the value is set to `true`, any * hostname is allowed. * * ```js * { * server: { * allowedHosts: ['staging.example.com', 'qa.example.com'] * } * } * ``` */ /** * @docs * @name server.open * @type {string | boolean} * @default `false` * @version 4.1.0 * @description * Controls whether the dev server should open in your browser window on startup. * * Pass a full URL string (e.g. "http://example.com") or a pathname (e.g. "/about") to specify the URL to open. * * ```js * { * server: { open: "/about" } * } * ``` */ /** * @docs * @name server.headers * @typeraw {OutgoingHttpHeaders} * @default `{}` * @version 1.7.0 * @description * Set custom HTTP response headers to be sent in `astro dev` and `astro preview`. */ server?: ServerConfig | ((options: { command: 'dev' | 'preview'; }) => ServerConfig); /** * @docs * @kind heading * @version 5.7.0 * @name Session Options * @description * * Configures session storage for your Astro project. This is used to store session data in a persistent way, so that it can be accessed across different requests. * Some adapters may provide a default session driver, but you can override it with your own configuration. * * See [the sessions guide](https://docs.astro.build/en/guides/sessions/) for more information. * * ```js title="astro.config.mjs" * { * session: { * // The name of the Unstorage driver * driver: 'redis', * // The required options depend on the driver * options: { * url: process.env.REDIS_URL, * }, * ttl: 3600, // 1 hour * } * } * ``` */ session?: SessionConfig<TSession>; /** * @docs * @name session.driver * @type {string | undefined} * @version 5.7.0 * @description * * The Unstorage driver to use for session storage. The [Node](https://docs.astro.build/en/guides/integrations-guide/node/#sessions), * [Cloudflare](https://docs.astro.build/en/guides/integrations-guide/cloudflare/#sessions), and * [Netlify](/en/guides/integrations-guide/netlify/#sessions) adapters automatically configure a default driver for you, * but you can specify your own if you would prefer or if you are using an adapter that does not provide one. * * The value is the "Driver name" from the [Unstorage driver documentation](https://unstorage.unjs.io/drivers). * * ```js title="astro.config.mjs" ins={4} * { * adapter: vercel(), * session: { * driver: "redis", * }, * } * ``` * :::note * Some drivers may need extra packages to be installed. Some drivers may also require environment variables or credentials to be set. See the [Unstorage documentation](https://unstorage.unjs.io/drivers) for more information. * ::: * */ /** * @docs * @name session.options * @type {Record<string, unknown> | undefined} * @version 5.7.0 * @default `{}` * @description * * The driver-specific options to use for session storage. The options depend on the driver you are using. See the [Unstorage documentation](https://unstorage.unjs.io/drivers) * for more information on the options available for each driver. * * ```js title="astro.config.mjs" ins={4-6} * { * session: { * driver: "redis", * options: { * url: process.env.REDIS_URL * }, * } * } * ``` */ /** * @docs * @name session.cookie * @type {string | AstroCookieSetOptions | undefined} * @version 5.7.0 * @default `{ name: "astro-session", sameSite: "lax", httpOnly: true, secure: true }` * @description * * The session cookie configuration. If set to a string, it will be used as the cookie name. * Alternatively, you can pass an object with additional options. These will be merged with the defaults. * * ```js title="astro.config.mjs" ins={3-4} * { * session: { * // If set to a string, it will be used as the cookie name. * cookie: "my-session-cookie", * } * } * * ``` * * ```js title="astro.config.mjs" ins={4-8} * { * session: { * // If set to an object, it will be used as the cookie options. * cookie: { * name: "my-session-cookie", * sameSite: "lax", * secure: true, * } * } * } * ``` */ /** * @docs * @name session.ttl * @version 5.7.0 * @type {number | undefined} * @default {Infinity} * @description * * An optional default time-to-live expiration period for session values, in seconds. * * By default, session values persist until they are deleted or the session is destroyed, and do not automatically expire because a particular amount of time has passed. * Set `session.ttl` to add a default expiration period for your session values. Passing a `ttl` option to [`session.set()`](https://docs.astro.build/en/reference/api-reference/#set) will override the global default * for that individual entry. * * ```js title="astro.config.mjs" ins={3-4} * { * session: { * // Set a default expiration period of 1 hour (3600 seconds) * ttl: 3600, * } * } * ``` * :::note * Setting a value for `ttl` does not automatically delete the value from storage after the time limit has passed. * * Values from storage will only be deleted when there is an attempt to access them after the `ttl` period has expired. At this time, the session value will be undefined and only then will the value be deleted. * * Individual drivers may also support a `ttl` option that will automatically delete sessions after the specified time. See your chosen driver's documentation for more information. * ::: */ /** * @docs * @kind heading * @name Dev Toolbar Options */ devToolbar?: { /** * @docs * @name devToolbar.enabled * @type {boolean} * @default `true` * @description * 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. * * This option is scoped to the entire project, to only disable the toolbar for yourself, run `npm run astro preferences disable devToolbar`. To disable the toolbar for all your Astro projects, run `npm run astro preferences disable devToolbar --global`. */ enabled: boolean; }; /** * @docs * @kind heading * @name Prefetch Options * @type {boolean | object} * @description * Enable prefetching for links on your site to provide faster page transitions. * (Enabled by default on pages using the `<ClientRouter />` router. Set `prefetch: false` to opt out of this behaviour.) * * This configuration automatically adds a prefetch script to every page in the project * giving you access to the `data-astro-prefetch` attribute. * Add this attribute to any `<a />` link on your page to enable prefetching for that page. * * ```html * <a href="/about" data-astro-prefetch>About</a> * ``` * Further customize the default prefetching behavior using the [`prefetch.defaultStrategy`](#prefetchdefaultstrategy) and [`prefetch.prefetchAll`](#prefetchprefetchall) options. * * See the [Prefetch guide](https://docs.astro.build/en/guides/prefetch/) for more information. */ prefetch?: boolean | { /** * @docs * @name prefetch.prefetchAll * @type {boolean} * @description * Enable prefetching for all links, including those without the `data-astro-prefetch` attribute. * This value defaults to `true` when using the `<ClientRouter />` router. Otherwise, the default value is `false`. * * ```js * prefetch: { * prefetchAll: true * } * ``` * * When set to `true`, you can disable prefetching individually by setting `data-astro-prefetch="false"` on any individual links. * * ```html * <a href="/about" data-astro-prefetch="false">About</a> *``` */ prefetchAll?: boolean; /** * @docs * @name prefetch.defaultStrategy * @type {'tap' | 'hover' | 'viewport' | 'load'} * @default `'hover'` * @description * The default prefetch strategy to use when the `data-astro-prefetch` attribute is set on a link with no value. * * - `'tap'`: Prefetch just before you click on the link. * - `'hover'`: Prefetch when you hover over or focus on the link. (default) * - `'viewport'`: Prefetch as the links enter the viewport. * - `'load'`: Prefetch all links on the page after the page is loaded. * * You can override this default value and select a different strategy for any individual link by setting a value on the attribute. * * ```html * <a href="/about" data-astro-prefetch="viewport">About</a> * ``` */ defaultStrategy?: 'tap' | 'hover' | 'viewport' | 'load'; }; /** * @docs * @kind heading * @name Image Options */ image?: { /** * @docs * @name image.endpoint * @type {{route: string, entrypoint: undefined | string}} * @default `{route: '/_image', entrypoint: undefined}` * @version 3.1.0 * @description * Set the endpoint to use for image optimization in dev and SSR. The `entrypoint` property can be set to `undefined` to use the default image endpoint. * * ```js * { * image: { * // Example: Use a custom image endpoint at `/custom_endpoint` * endpoint: { * route: '/custom_endpoint', * entrypoint: 'src/my_endpoint.ts', * }, * }, * } * ``` */ endpoint?: { route: '/_image' | (string & {}); entrypoint: undefined | string; }; /** * @docs * @name image.service * @type {{entrypoint: 'astro/assets/services/sharp' | string, config: Record<string, any>}} * @default `{entrypoint: 'astro/assets/services/sharp', config?: {}}` * @version 2.1.0 * @description * Set which image service is used for Astro’s assets support. * * The value should be an object with an entrypoint for the image service to use and optionally, a config object to pass to the service. * * The service entrypoint can be either one of the included services, or a third-party package. * * ```js * { * image: { * // Example: Enable the Sharp-based image service with a custom config * service: { * entrypoint: 'astro/assets/services/sharp', * config: { * limitInputPixels: false, * }, * }, * }, * } * ``` */ service?: ImageServiceConfig; /** * @docs * @name image.service.config.limitInputPixels * @kind h4 * @type {number | boolean} * @default `true` * @version 4.1.0 * @description * * Whether or not to limit the size of images that the Sharp image service will process. * * Set `false` to bypass the default image size limit for the Sharp image service and process large images. */ /** * @docs * @name image.domains * @type {string[]} * @default `[]` * @version 2.10.10 * @description * Defines a list of permitted image source domains for remote image optimization. No other remote images will be optimized by Astro. * * This option requires an array of individual domain names as strings. Wildcards are not permitted. Instead, use [`image.remotePatterns`](#imageremotepatterns) to define a list of allowed source URL patterns. * * ```js * // astro.config.mjs * { * image: { * // Example: Allow remote image optimization from a single domain * domains: ['astro.build'], * }, * } * ``` */ domains?: string[]; /** * @docs * @name image.remotePatterns * @type {RemotePattern[]} * @default `[]` * @version 2.10.10 * @description * Defines a list of permitted image source URL patterns for remote image optimization. * * `remotePatterns` can be configured with four properties: * 1. protocol * 2. hostname * 3. port * 4. pathname * * ```js * { * image: { * // Example: allow processing all images from your aws s3 bucket * remotePatterns: [{ * protocol: 'https', * hostname: '**.amazonaws.com', * }], * }, * } * ``` * * You can use wildcards to define the permitted `hostname` and `pathname` values as described below. Otherwise, only the exact values provided will be configured: * `hostname`: * - Start with '**.' to allow all subdomains ('endsWith'). * - Start with '*.' to allow only one level of subdomain. * * `pathname`: * - End with '/**' to allow all sub-routes ('startsWith'). * - End with '/*' to allow only one level of sub-route. */ remotePatterns?: Partial<RemotePattern>[]; /** * @docs * @name image.experimentalLayout * @type {ImageLayout} * @default `undefined` * @description * The default layout type for responsive images. Can be overridden by the `layout` prop on the image component. * Requires the `experimental.responsiveImages` flag to be enabled. * - `constrained` - The image will scale to fit the container, maintaining its aspect ratio, but will not exceed the specified dimensions. * - `fixed` - The image will maintain its original dimensions. * - `full-width` - The image will scale to fit the container, maintaining its aspect ratio. */ experimentalLayout?: ImageLayout | undefined; /** * @docs * @name image.experimentalObjectFit * @type {ImageFit} * @default `"cover"` * @description * The default object-fit value for responsive images. Can be overridden by the `fit` prop on the image component. * Requires the `experimental.responsiveImages` flag to be enabled. */ experimentalObjectFit?: ImageFit; /** * @docs * @name image.experimentalObjectPosition * @type {string} * @default `"center"` * @description * The default object-position value for responsive images. Can be overridden by the `position` prop on the image component. * Requires the `experimental.responsiveImages` flag to be enabled. */ experimentalObjectPosition?: string; /** * @docs * @name image.experimentalBreakpoints * @type {number[]} * @default `[640, 750, 828, 1080, 1280, 1668, 2048, 2560] | [640, 750, 828, 960, 1080, 1280, 1668, 1920, 2048, 2560, 3200, 3840, 4480, 5120, 6016]` * @description * The breakpoints used to generate responsive images. Requires the `experimental.responsiveImages` flag to be enabled. The full list is not normally used, * but is filtered according to the source and output size. The defaults used depend on whether a local or remote image service is used. For remote services * the more comprehensive list is used, because only the required sizes are generated. For local services, the list is shorter to reduce the number of images generated. */ experimentalBreakpoints?: number[]; }; /** * @docs * @kind heading * @name Markdown Options */ markdown?: { /** * @docs * @name markdown.shikiConfig * @typeraw {Partial<ShikiConfig>} * @description * * Shiki is our default syntax highlighter. You can configure all options via the `markdown.shikiConfig` object: * * ```js title="astro.config.mjs" * import { defineConfig } from 'astro/config'; * * export default defineConfig({ * markdown: { * shikiConfig: { * // Choose from Shiki's built-in themes (or add your own) * // https://shiki.style/themes * theme: 'dracula', * // Alternatively, provide multiple themes * // See note below for using dual light/dark themes * themes: { * light: 'github-light', * dark: 'github-dark', * }, * // Disable the default colors * // https://shiki.style/guide/dual-themes#without-default-color * // (Added in v4.12.0) * defaultColor: false, * // Add custom languages * // Note