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 { CspAlgorithm, CspDirective, CspHash } from '../../core/csp/config.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 }; export type { CspAlgorithm }; type NormalizeLocales = { [K in keyof T]: T[K] extends string ? T[K] : T[K] extends { codes: Array; } ? T[K]['codes'][number] : never; }[number]; export interface ImageServiceConfig = Record> { 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 & { 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 extends CommonSessionConfig { driver: TDriver; options?: BuiltinDriverOptions[TDriver]; } interface CustomSessionConfig extends CommonSessionConfig { /** Entrypoint for a custom session driver */ driver?: string; options?: Record; } interface TestSessionConfig extends CommonSessionConfig { driver: 'test'; options: { mockStorage: Storage; }; } export type SessionConfig = [ TDriver ] extends [never] ? CustomSessionConfig : TDriver extends keyof BuiltinDriverOptions ? BuiltinSessionConfig : TDriver extends 'test' ? TestSessionConfig : CustomSessionConfig; export type ResolvedSessionConfig = SessionConfig & { 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 { /** * @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} * @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 [`` 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; /** * @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; /** * @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} * @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 ` * * ``` * * By default, it will generate a CSS style where `red` will be applied: * * ```css * body {background:#ff0} body {background:red} * ``` * * When this new option is set to `true`, the generated CSS style will apply `yellow`: * * ```css * body {background:red} body {background:#ff0} * ``` * */ preserveScriptOrder?: boolean; /** * @name experimental.liveContentCollections * @type {boolean} * @default `false` * @version 5.10 * @description * Enables the use of live content collections. * */ liveContentCollections?: boolean; /** * @name experimental.staticImportMetaEnv * @type {boolean} * @default `false` * @version 5.13 * @description * * Disables replacement of `import.meta.env` values with `process.env` calls and their coercion * * Currently, non-public `import.meta.env` environment variables are replaced by a reference to `process.env`. Additionally, Astro may also convert the value type of your environment variables used through `import.meta.env`, which can prevent access to some values such as the strings `"true"` (which is converted to a boolean value), and `"1"` (which is converted to a number). * * The `experimental.staticImportMetaEnv` flag simplifies Astro's default behavior, making it easier to understand and use. Astro will no longer replace any `import.meta.env` environment variables with a `process.env` call, nor will it coerce values. * * This flag aligns `import.meta.env`'s behavior in Astro with [Vite](https://vite.dev/guide/env-and-mode.html#env-variables). * * See the [experimental static `import.meta.env` docs](https://docs.astro.build/en/reference/experimental-flags/static-import-meta-env/) for more information. */ staticImportMetaEnv?: boolean; /** * @name experimental.chromeDevtoolsWorkspace * @type {boolean} * @default `false` * @version 5.13 * @description * * Enables Chrome DevTools workspace integration for the Astro dev server. * * When enabled, the dev server will automatically configure a [Chrome DevTools workspace](https://developer.chrome.com/docs/devtools/workspaces) for your project, * allowing you to edit files directly in the browser and have those changes reflected in your local file system. * * ```js * import { defineConfig } from 'astro/config'; * * export default defineConfig({ * experimental: { * chromeDevtoolsWorkspace: true, * }, * }); * ``` * * See the [experimental Chrome DevTools workspace feature documentation](https://docs.astro.build/en/reference/experimental-flags/chrome-devtools-workspace/) for more information. */ chromeDevtoolsWorkspace?: boolean; }; } /** * Resolved Astro Config * * Config with user settings along with all defaults filled in. */ export interface AstroConfig extends AstroConfigType { integrations: AstroIntegration[]; } /** * An inline Astro config that takes highest priority when merging with the user config, * and includes inline-specific options to configure how Astro runs. */ export interface AstroInlineConfig extends AstroUserConfig, AstroInlineOnlyConfig { } export interface AstroInlineOnlyConfig { /** * A custom path to the Astro config file. If relative, it'll resolve based on the current working directory. * Set to false to disable loading any config files. * * If this value is undefined or unset, Astro will search for an `astro.config.(js,mjs,ts)` file relative to * the `root` and load the config file if found. * * The inline config passed in this object will take the highest priority when merging with the loaded user config. */ configFile?: string | false; /** * The mode used when developing or building your site. It's passed to Vite that affects the value of `import.meta.env.MODE` * and how `.env` files are loaded, which also affects the values of `astro:env`. See the * [environment variables documentation](https://docs.astro.build/en/guides/environment-variables/) for more details. * * To output a development-based build, you can run `astro build` with the `--devOutput` flag. * * @default "development" for `astro dev`, "production" for `astro build` */ mode?: string; /** * The logging level to filter messages logged by Astro. * - "debug": Log everything, including noisy debugging diagnostics. * - "info": Log informational messages, warnings, and errors. * - "warn": Log warnings and errors. * - "error": Log errors only. * - "silent": No logging. * * @default "info" */ logLevel?: LoggerLevel; /** * Clear the content layer cache, forcing a rebuild of all content entries. */ force?: boolean; }