# @astrojs/deno 中文文档

规范地址：https://npmcn.com/package/%40astrojs/deno/

版本：5\.0\.1
npm 元数据更新时间：2025-09-18T17:31:52.902Z
中文译文更新时间：2026-11-07T01:27:48.180Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40astrojs/deno
原文对照：https://npmcn.com/package/%40astrojs/deno/?lang=original
项目主页：https://docs.astro.build/en/guides/integrations-guide/deno/
源码仓库：https://github.com/withastro/astro

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：19.1 kB，11 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：1 个
- peer 依赖：astro ^3\.1\.4
- 首次发布：2022-04-02T19:59:56.267Z
- 最新版本发布：2023-09-25T19:57:12.816Z
- 近 30 天下载量：2286（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：57（近 12 个月 0 个）

## 中文简介

将您的站点部署到 Deno 服务器

## 安装

```sh
npm install @astrojs/deno
```

也可以使用：`pnpm add @astrojs/deno`、`yarn add @astrojs/deno`、`bun add @astrojs/deno`

## README

# 」

这个适配器可以让Astro将你的SSR站点部署到德诺目标.

学着如何在我们的星座上部署 [Deno部署指南](https://docs.astro.build/en/guides/deploy/deno/)。 。 。 .

-   **[为什么是Astro Deno](https://npmcn.com/package/%40astrojs/deno/#readme-why-astro-deno)**
-   **[安装](https://npmcn.com/package/%40astrojs/deno/#readme-installation)**
-   **[使用量](https://npmcn.com/package/%40astrojs/deno/#readme-usage)**
-   **[配置](https://npmcn.com/package/%40astrojs/deno/#readme-configuration)**
-   **[实例](https://npmcn.com/package/%40astrojs/deno/#readme-examples)**
-   **[解决问题](https://npmcn.com/package/%40astrojs/deno/#readme-troubleshooting)**
-   **[捐款](https://npmcn.com/package/%40astrojs/deno/#readme-contributing)**
-   **[更改日志](https://npmcn.com/package/%40astrojs/deno/#readme-changelog)**

## 为什么是Astro Deno

如果你把Astro当作一个静态的站点建造者.

如果你愿意的话 [使用服务器侧渲染( SSR)](https://docs.astro.build/en/guides/server-side-rendering/),Astro需要一个匹配您的部署运行时间的适配器.

[德诺](https://deno.land/) 是一个类似于节点的运行时间,但有一个更类似于浏览器的API的API. 这个适配器提供了对德诺的API的访问,并创建了脚本来在德诺服务器上运行您的项目.

## 安装

添加 Deno 适配器, 在您的 Astro 项目中启用 SSR 如下 `astro add` 命令。 这将安装适配器并对您的 `astro.config.mjs` 以步骤存档.

```sh
# Using NPM
npx astro add deno
# Using Yarn
yarn astro add deno
# Using PNPM
pnpm astro add deno
```

如果您宁愿手动安装适配器,请完成以下两个步骤:

1.  使用您首选的软件包管理器安装项目依赖的 Deno 适配器 。 如果您使用 npm 或不确定, 请在终端运行 :
    
    ```bash
      npm install @astrojs/deno
    ```
    
2.  更新您的 `astro.config.mjs` 以下更改的项目配置文件.
    
    ```js
    // astro.config.mjs
    import { defineConfig } from 'astro/config';
    import deno from '@astrojs/deno';
    
    export default defineConfig({
      output: 'server',
      adapter: deno(),
    });
    ```
    

下一个,更新您的 `preview` 脚本在 `package.json` 要运行 `deno`数字 :

```json
// package.json
{
  // ...
  "scripts": {
    "dev": "astro dev",
    "start": "astro dev",
    "build": "astro build",
    "preview": "deno run --allow-net --allow-read --allow-env ./dist/server/entry.mjs"
  }
}
```

您现在可以使用此命令在本地预览您的生产 Astro 站点 .

```bash
npm run preview
```

## 使用量

之后 [执行构建](https://docs.astro.build/en/guides/deploy/#building-your-site-locally) 将有一个 `dist/server/entry.mjs` 模块。 您可以在您的 Deno 应用程序中导入此模块来启动服务器 :

```js
import './dist/server/entry.mjs';
```

见 `start` 选项,用于您如何对启动 Astro 服务器拥有更多的控制.

您也可以直接使用 deno 运行脚本 :

```sh
deno run --allow-net --allow-read --allow-env ./dist/server/entry.mjs
```

## 配置

要配置此适配器, 将对象传递到 `deno()` 函数调用 `astro.config.mjs`。 。 。 .

```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import deno from '@astrojs/deno';

export default defineConfig({
  output: 'server',
  adapter: deno({
    //options go here
  }),
});
```

### 开始

此适配器在导入时会自动启动服务器 。 你可以关掉这个 `start` 选项 :

```js
import { defineConfig } from 'astro/config';
import deno from '@astrojs/deno';

export default defineConfig({
  output: 'server',
  adapter: deno({
    start: false,
  }),
});
```

如果您禁用此功能, 您需要写入您的 Deno 网络服务器 。 导入和呼叫 `handle` 从生成的条目脚本中获取请求:

```ts
import { serve } from 'https://deno.land/std@0.167.0/http/server.ts';
import { handle } from './dist/server/entry.mjs';

serve((req: Request) => {
  // Check the request, maybe do static file handling here.

  return handle(req);
});
```

### 端口和主机名称

您可以设置端口( 默认 ): `8085`)和主机名(默认: `0.0.0.0`)用于 deno 服务器. 若为 `start` 错误, 这没有效果; 您的服务器必须配置端口和主机名 .

```js
import { defineConfig } from 'astro/config';
import deno from '@astrojs/deno';

export default defineConfig({
  output: 'server',
  adapter: deno({
    port: 8081,
    hostname: 'myhost',
  }),
});
```

## 实例

这个 [Astro 德诺](https://github.com/withastro/astro/tree/main/examples/deno) 实例包括: `preview` 命令直接运行条目脚本。 运行 `npm run build` 接下来 `npm run preview` 运行生产 deno 服务器.

## 解决问题

帮我看看 `#support` 频道打开 [解析器](https://astro.build/chat)我们友好的支援队成员来帮忙!

你也可以检查我们 [Astro 集成文档](https://docs.astro.build/en/guides/integrations-guide/) 更多关于融合.

## 捐款

这个包由Astro的核心团队维护. 欢迎你提交一个问题或公关!

## 更改日志

见 [变动情况](https://npmcn.com/package/%40astrojs/deno/CHANGELOG.md) 以了解这种融合的变化历史.

## 常见问题

### @astrojs/deno 是什么？

将您的站点部署到 Deno 服务器

### 如何安装 @astrojs/deno？

在项目目录运行 npm install @astrojs/deno，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：astro（^3\.1\.4）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @astrojs/deno 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @astrojs/deno 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @astrojs/deno 可以商用吗？

@astrojs/deno 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @astrojs/deno 的下载量有多少？

根据 npm 官方下载统计，@astrojs/deno 在 2026/10/07 – 2026/11/05 这 30 天内被下载 2,286 次，日均约 76 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @astrojs/deno 还在维护吗？

最新版本 5\.0\.1 发布于 2023/09/26（3 年前）；至今共发布 57 个版本，其中过去 12 个月发布了 0 个；首次发布于 2022/04/03。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

