Astro 2.2

By
Matthew Phillips

Astro 2.2 is out! Included in this release are:

Additionally, Astro 2.2 includes 8 patch changes and was released alongside 8 integrations with patch releases.

Run npm i astro@latest to upgrade to the latest version.

CDN support

In 2.2 you can now configure Astro to point to a CDN in order to load your assets. In your Astro config:

import { defineConfig } from "astro/config"

export default defineConfig({
	build: {
		assetsPrefix: "https://cdn.example.com",
	},
})

The links for any assets, scripts, and stylesheets after running astro build will be prefixed with the configured URL. This applies to both SSG and SSR modes.

<link rel="stylesheet" href="https://cdn.example.com/_astro/global.css" />

The assets are still built to your dist/ folder, like always. You will need to configure your deployment scripts to deploy dist/_astro/ to your CDN.

image() schema API change

In 2.2 the image() schema helper in the experimental assets API has been moved to a callback where the schema is defined.

import { defineCollection, z } from "astro:content"

const blog = defineCollection({
	schema: ({ image }) =>
		z.object({
			image: image().refine((img) => img.width >= 200, {
				message: "image too small",
			}),
		}),
})

Previously, image() was imported directly from 'astro:content'. However, this created bugs where Astro was not able to correctly resolve relative image assets defined in the frontmatter. Providing the helper as a callback aligns with how Zod suggests implementing contextual references.

This new callback based schema assignment is currently only available with experimental assets enabled. If you are not using the image() helper, you can continue to assign the schemas directly to the schema property on the collection.

Try Astro 2.2

Thank you to everyone who contributed to this outstanding release. In addition to these new features, there were also several bug fixes throughout the core packages and integrations. See the complete release notes to learn more.