@astrojs/deno

中文文档
5.0.1发布于 2023/09/26MITTypeScriptES Module近 30 天下载 2286

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

中文使用文档
文档目录10 节
  1. 为什么是Astro Deno
  2. 安装
  3. 使用量
  4. 配置
  5. 开始
  6. 端口和主机名称
  7. 实例
  8. 解决问题
  9. 捐款
  10. 更改日志

」

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

学着如何在我们的星座上部署 Deno部署指南。 。 。 .

为什么是Astro Deno

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

如果你愿意的话 使用服务器侧渲染( SSR),Astro需要一个匹配您的部署运行时间的适配器.

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

安装

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

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

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

  1. 使用您首选的软件包管理器安装项目依赖的 Deno 适配器 。 如果您使用 npm 或不确定, 请在终端运行 :

      npm install @astrojs/deno
    
  2. 更新您的 astro.config.mjs 以下更改的项目配置文件.

    // astro.config.mjs
    import { defineConfig } from 'astro/config';
    import deno from '@astrojs/deno';
    
    export default defineConfig({
      output: 'server',
      adapter: deno(),
    });
    

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

// 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 站点 .

npm run preview

使用量

之后 执行构建 将有一个 dist/server/entry.mjs 模块。 您可以在您的 Deno 应用程序中导入此模块来启动服务器 :

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

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

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

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

配置

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

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

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

开始

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

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

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

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

import { serve } from 'https://deno.land/[email protected]/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 错误, 这没有效果; 您的服务器必须配置端口和主机名 .

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

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

实例

这个 Astro 德诺 实例包括: preview 命令直接运行条目脚本。 运行 npm run build 接下来 npm run preview 运行生产 deno 服务器.

解决问题

帮我看看 #support 频道打开 解析器我们友好的支援队成员来帮忙!

你也可以检查我们 Astro 集成文档 更多关于融合.

捐款

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

更改日志

见 变动情况 以了解这种融合的变化历史.

版本与发布记录

@astrojs/deno 共发布 57 个版本,首次发布于 2022/04/03;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.0.1latest2023/09/263 年前
5.0.02023/08/303 年前
5.0.0-rc.22023/08/293 年前
5.0.0-rc.12023/08/223 年前
5.0.0-beta.02023/08/033 年前
4.3.02023/07/263 年前

其他发布通道:next--rc → 0.0.0-rc-20220726043527,next--imgcache → 0.0.0-imgcache-20220929145446,next--node-standalone → 0.0.0-node-standalone-20221011210529,next--error-overlay → 0.0.0-error-overlay-20221203190718,next--join-base → 0.0.0-join-base-20221208170900,next--content-schemas → 0.0.0-content-schemas-20221209180144。

关于 @astrojs/deno 的常见问题

@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 和提交记录判断。