Skip to content

Commit 6a6b6d0

Browse files
authored
Update cloudflare.mdx from withastro#11497
1 parent bf0a815 commit 6a6b6d0

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/content/docs/zh-cn/guides/integrations-guide/cloudflare.mdx

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
type: integration
33
title: '@astrojs/cloudflare'
4-
description: 了解如何使用 @astrojs/cloudflare SSR 适配器来部署你的 Astro 项目。
4+
description: 了解如何使用 @astrojs/cloudflare 适配器来部署你的 Astro 项目。
55
sidebar:
66
label: Cloudflare
77
githubIntegrationURL: 'https://github.com/withastro/astro/tree/main/packages/integrations/cloudflare/'
@@ -14,9 +14,9 @@ import ReadMore from '~/components/ReadMore.astro';
1414
import Since from '~/components/Since.astro';
1515
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
1616

17-
此适配器允许 Astro 将你的 [按需渲染路由](/zh-cn/guides/on-demand-rendering/)部署到[Cloudflare](https://www.cloudflare.com/).
17+
此适配器允许 Astro 将你的 [按需渲染路由及其功能](/zh-cn/guides/on-demand-rendering/)部署到 [Cloudflare](https://www.cloudflare.com/),包括 [服务器群岛](/zh-cn/guides/server-islands/)[actions](/zh-cn/guides/actions/) 以及 [sessions](/zh-cn/guides/sessions/)
1818

19-
如果你使用 Astro 作为静态站点构建器,则不需要适配器来部署 Cloudflare
19+
如果你只是将 Astro 作为静态的站点构建器,则不需要适配器
2020

2121
在我们的 [Cloudflare Pages 部署指南](/zh-cn/guides/deploy/cloudflare/) 中了解如何部署 Astro 站点。
2222

@@ -28,7 +28,7 @@ Cloudflare 的 [开发者平台](https://developers.cloudflare.com/) 为用户
2828

2929
Astro 包含了一个 `astro add` 命令,用于自动设置官方集成。如果你愿意,可以改为 [手动安装集成](#手动安装)
3030

31-
在你的 Astro 项目中使用 `astro add` 命令添加 Cloudflare 适配器,以启用 SSR。这将安装`@astrojs/cloudflare` 并一步到位地对你的 `astro.config.mjs` 文件进行相应的更改。
31+
在你的 Astro 项目中使用 `astro add` 命令添加 Cloudflare 适配器,以启用服务器端渲染。这将安装 `@astrojs/cloudflare` 并一步到位地对你的 `astro.config.mjs` 文件进行相应的更改。
3232

3333
<PackageManagerTabs>
3434
<Fragment slot="npm">
@@ -48,6 +48,8 @@ Astro 包含了一个 `astro add` 命令,用于自动设置官方集成。如
4848
</Fragment>
4949
</PackageManagerTabs>
5050

51+
现在,你可以启用 [对每个页面的按需渲染](/zh-cn/guides/on-demand-rendering/#启用按需渲染),或者将你的构建输出配置设置为 `output: 'server'` 从而 [默认对所有页面都进行服务器端渲染](/zh-cn/guides/on-demand-rendering/#server-模式)
52+
5153
### 手动安装
5254

5355
首先,使用合适的包管理器将 `@astrojs/cloudflare` 适配器添加到项目的依赖项中。
@@ -70,14 +72,13 @@ Astro 包含了一个 `astro add` 命令,用于自动设置官方集成。如
7072
</Fragment>
7173
</PackageManagerTabs>
7274

73-
然后,将适配器和所需的[按需渲染模式](/zh-cn/guides/on-demand-rendering/)添加到 `astro.config.mjs` 文件中:
75+
然后,将适配器添加到 `astro.config.mjs` 文件中:
7476

75-
```js title="astro.config.mjs" ins={2,5-6}
77+
```js title="astro.config.mjs" ins={2,5}
7678
import { defineConfig } from 'astro/config';
7779
import cloudflare from '@astrojs/cloudflare';
7880

7981
export default defineConfig({
80-
output: 'server',
8182
adapter: cloudflare(),
8283
});
8384
```
@@ -108,7 +109,7 @@ Cloudflare 适配器接受以下选项:
108109

109110
* **`cloudflare`** 使用 [Cloudflare 图像调整](https://developers.cloudflare.com/images/image-resizing/) 服务。
110111
* **`passthrough`** 使用现有的 [`noop`](/zh-cn/guides/images/#配置-no-op-透传服务) 服务。
111-
* **`compile`** 使用 Astro 的默认服务(sharp),但仅在构建时对预渲染的路由有效。在服务端渲染(SSR)中,对按需渲染的页面,所有 `astro:assets` 功能都将被禁用。
112+
* **`compile`** 使用 Astro 的默认服务(sharp),但仅在构建时对预渲染的路由有效。对按需渲染的页面,所有 `astro:assets` 功能都将被禁用。
112113
* **`custom`** 总是使用在 [Image 选项](/zh-cn/reference/configuration-reference/#image-选项) 中配置的图像服务。**此选项不会检查配置的图像服务是否在 Cloudflare 的 `workerd` 运行时中工作。**
113114

114115
```js title="astro.config.mjs" ins={6}
@@ -119,7 +120,6 @@ export default defineConfig({
119120
adapter: cloudflare({
120121
imageService: 'cloudflare'
121122
}),
122-
output: 'server'
123123
})
124124
```
125125

@@ -214,15 +214,15 @@ export default defineConfig({
214214
**默认值:** `undefined`
215215
</p>
216216

217-
`routes.extend.exclude` 数组中配置要从按需渲染中排除的路由。这些路由将预先渲染并以静态方式提供,而不会调用服务端渲染(SSR)函数。此外,你还可以使用这个选项直接提供任何静态资源(例如:图片、字体、css、js、html、txt、json 等)文件,无需通过 SSR 函数路由请求
217+
`routes.extend.exclude` 数组中配置要从按需渲染中排除的路由。这些路由将预先渲染并以静态方式提供,而不会调用服务端函数。此外,你还可以使用这个选项直接提供任何静态资源(例如:图片、字体、css、js、html、txt、json 等)文件,无需通过服务端函数路由请求
218218

219219
```js title="astro.config.mjs"
220220

221221
export default defineConfig({
222222
adapter: cloudflare({
223223
routes: {
224224
extend: {
225-
include: [{ pattern: '/static' }], // 将预渲染的页面路由到服务端渲染函数以实现按需渲染
225+
include: [{ pattern: '/static' }], // 将预渲染的页面路由到服务端函数以实现按需渲染
226226
exclude: [{ pattern: '/pagefind/*' }], // 使用 Starlight 的 pagefind 搜索,该搜索在构建时静态生成
227227
}
228228
},
@@ -372,7 +372,7 @@ declare namespace App {
372372

373373
#### Cloudflare Workers 路由
374374

375-
静态资源的路由是基于构建目录(例如 `./dist`)的文件结构的。如果不匹配,将会回退至 SSR 的 Worker。更多内容详见 [Cloudflare Workers 静态资源路由](https://developers.cloudflare.com/workers/static-assets/routing/)
375+
静态资源的路由是基于构建目录(例如 `./dist`)的文件结构的。如果不匹配,将会回退至按需渲染的 Worker。更多内容详见 [Cloudflare Workers 静态资源路由](https://developers.cloudflare.com/workers/static-assets/routing/)
376376

377377
不同于 [Cloudflare Pages](#cloudflare-pages-路由),使用 Workers 时,无需 `_routes.json` 文件。
378378

@@ -485,13 +485,12 @@ import { Buffer } from 'node:buffer';
485485

486486
你还需要修改你的 Astro 配置中的 `vite` 配置,以允许使用 `node:*` 导入语法:
487487

488-
```js title="astro.config.mjs" ins={7-11}
488+
```js title="astro.config.mjs" ins={6-10}
489489
import { defineConfig } from "astro/config";
490490
import cloudflare from '@astrojs/cloudflare';
491491

492492
export default defineConfig({
493493
adapter: cloudflare({}),
494-
output: 'server',
495494
vite: {
496495
ssr: {
497496
external: ['node:buffer'],
@@ -528,10 +527,9 @@ export default defineConfig({
528527

529528
目前,在 Wrangler 中运行应用程序时由于代码被压缩,错误消息并不是很有用。为了更好地进行调试,你可以将 `vite.build.minify = false` 添加到你的 `astro.config.js` 文件中。
530529

531-
```js title="astro.config.mjs" ins={4-8}
530+
```js title="astro.config.mjs" ins={3-7}
532531
export default defineConfig({
533532
adapter: cloudflare(),
534-
output: 'server',
535533
vite: {
536534
build: {
537535
minify: false,

0 commit comments

Comments
 (0)