Astro 2.2

作者
Matthew Phillips

Astro 2.2 已发布!此版本包括:

此外,Astro 2.2 还包含了 **8个补丁更改**,并与 **8个集成** 的补丁版本一同发布。

运行 `npm i astro@latest` 升级到最新版本。

CDN支持

在2.2版本中,您现在可以配置Astro指向CDN以加载您的资产。在您的Astro配置中:

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

运行 `astro build` 后,任何资产、脚本和样式表的链接都将以配置的URL为前缀。这适用于SSG和SSR模式。

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

资产仍像往常一样构建到您的 `dist/` 文件夹中。您需要配置部署脚本以将 `dist/_astro/` 部署到您的CDN。

image() 模式API变更

在2.2版本中,实验性资产API中的 `image()` 模式助手已移至定义模式的回调函数中。

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

此前,`image()` 是直接从 `'astro:content'` 导入的。然而,这导致了Astro无法正确解析在frontmatter中定义的相对图像资产的错误。将助手作为回调提供,符合Zod建议的上下文引用实现方式。

这种新的基于回调的模式分配目前仅在启用实验性资产时可用。如果您不使用 `image()` 助手,您可以继续直接将模式分配给集合上的 `schema` 属性。

尝试 Astro 2.2

感谢所有为本次卓越发布做出贡献的人。除了这些新功能外,核心包和集成中还修复了多个错误。有关更多信息,请参阅完整的发布说明