Skip to content

实验性序列化配置

类型:boolean
默认:false

¥Type: boolean
Default: false

Added in: astro@5.2.0

此功能允许访问 astro:config 虚拟模块,该模块通过两个子模块公开 Astro 配置的非详尽、可序列化、类型安全的版本。

¥This feature allows access to the astro:config virtual module which exposes a non-exhaustive, serializable, type-safe version of the Astro configuration through two sub-modules.

有关完整概述以及对此实验性 API 提供反馈,请参阅 序列化清单 RFC

¥For a complete overview, and to give feedback on this experimental API, see the Serialized Manifest RFC.

要启用此虚拟模块,请将 experimental.serializeConfig 功能标志添加到 Astro 配置中:

¥To enable this virtual module, add the experimental.serializeConfig feature flag to your Astro config:

astro.config.mjs
import { defineConfig } from "astro/config"
export default defineConfig({
experimental: {
serializeConfig: true
}
})

然后,Astro 项目中的任何文件都可以使用配置值:

¥Then, configuration values can be used by any file in your Astro project:

src/utils.js
import { trailingSlash } from "astro:config/client";
function addForwardSlash(path) {
if (trailingSlash === "always") {
return path.endsWith("/") ? path : path + "/"
} else {
return path
}
}

¥Submodules

虚拟模块公开两个子模块,用于访问配置值的不同子集。这通过仅向客户端提供一些数据来保护你的信息。

¥The virtual module exposes two submodules for accessing different subsets of your configuration values. This protects your information by only making some data available to the client.

可以从 astro:config/server 访问所有可用的配置值。但是,对于在客户端上执行的代码,只有 astro:config/client 公开的值才可用。

¥All available config values can be accessed from astro:config/server. However, for code executed on the client, only those values exposed by astro:config/client will be available.

客户端子模块允许你访问 astro:config/server 中可以安全地向浏览器公开的配置值子集,例如 trailingSlashbuild.formati18n 等。将此子模块用于在客户端上执行的客户端代码。

¥The client submodule allows you to access a subset of the configuration values in astro:config/server that are safe to expose to the browser such as trailingSlash, build.format, i18n, and more. Use this submodule for client side code that is executed on the client.

这是一项正在开发的功能。有关 astro:config/client 提供的配置值的完整最新列表,请参阅 来自的建议 API 功能 RFC

¥This is a developing feature. For a full, up-to-date list of the configuration values available from astro:config/client, please see the proposed API from the feature RFC

服务器子模块允许你从 astro.config.mjs 访问一组非详尽的配置值。这包括 astro:config/client 值(例如 trailingSlashi18n),还包括有关文件系统配置的更多敏感信息(例如 srcDircacheDiroutDir),这些信息不安全,不适合向客户端公开。尝试在客户端上使用它们将引发错误。

¥The server submodule allows you to access a non-exhaustive set of your configuration values from astro.config.mjs. This includes astro:config/client values such as trailingSlash and i18n, but also more sensitive information about your file system configuration that is not safe to expose to the client such as srcDir, cacheDir, outDir. Attempting to use them on the client will raise an error.

这是一项正在开发的功能。有关 astro:config/server 提供的配置值的完整最新列表,请参阅 来自的建议 API 功能 RFC

¥This is a developing feature. For a full, up-to-date list of the configuration values available from astro:config/server, please see the proposed API from the feature RFC.

Astro v5.5 中文网 - 粤ICP备13048890号