deno.com
本页内容

打包器

命令行用法

deno bundle [OPTIONS] [file]...

输出包含所有依赖项的单个 JavaScript 文件。

deno bundle jsr:@std/http/file-server -o file-server.bundle.js

如果未指定输出文件,则输出将写入标准输出

deno bundle jsr:@std/http/file-server


类型检查选项 Jump to heading

--check Jump to heading

启用类型检查。此子命令默认不进行类型检查。如果提供“all”值,将包括远程模块。或者,可以使用“deno check”子命令。

--no-check Jump to heading

跳过类型检查。如果提供“remote”值,将忽略来自远程模块的诊断错误。

依赖管理选项 Jump to heading

--frozen Jump to heading

如果锁定文件过期,则报错。

--import-map Jump to heading

从本地文件或远程 URL 加载导入映射文件。

--lock Jump to heading

检查指定的锁定文件。(如果未提供值,则默认为“./deno.lock”)。

--no-lock Jump to heading

禁用锁定文件的自动发现。

--no-npm Jump to heading

不解析 npm 模块。

--no-remote Jump to heading

不解析远程模块。

--node-modules-dir Jump to heading

设置 npm 包的 node 模块管理模式。

--reload Jump to heading

短标记:-r

重新加载源代码缓存(重新编译 TypeScript)无值 重新加载所有内容 jsr:@std/http/file-server,jsr:@std/assert/assert-equals 重新加载特定模块 npm: 重新加载所有 npm 模块 npm:chalk 重新加载特定 npm 模块。

--vendor Jump to heading

切换远程模块的本地 vendor 文件夹使用和 npm 包的 node_modules 文件夹使用。

选项 Jump to heading

--allow-import Jump to heading

短标记:-I

允许从远程主机导入。可选择指定允许的 IP 地址和主机名,必要时包括端口。默认值:deno.land:443,jsr.io:443,esm.sh:443,cdn.jsdelivr.net:443,raw.githubusercontent.com:443,user.githubusercontent.com:443

--allow-scripts Jump to heading

允许为给定包运行 npm 生命周期脚本 注意:脚本仅在使用 node_modules 目录 (--node-modules-dir) 时执行。

--cert Jump to heading

从 PEM 编码文件中加载证书颁发机构。

--code-splitting Jump to heading

启用代码拆分。

--conditions Jump to heading

使用此参数为 npm 包导出指定自定义条件。您也可以使用 DENO_CONDITIONS 环境变量。

--config Jump to heading

短标记:-c

配置 Deno 的不同方面,包括 TypeScript、代码检查和代码格式化。通常配置文件名为 deno.jsondeno.jsonc 并会自动检测;在这种情况下,此标记不是必需的。

--deny-import Jump to heading

拒绝从远程主机导入。可选择指定拒绝的 IP 地址和主机名,必要时包括端口。

--external Jump to heading

--format Jump to heading

--inline-imports Jump to heading

是否将导入的模块内联到导入文件中 [默认值: true]

--minify Jump to heading

压缩输出。

--no-config Jump to heading

禁用自动加载配置文件。

--outdir Jump to heading

捆绑文件的输出目录。

--output Jump to heading

短标记:-o

输出路径。

--packages Jump to heading

如何处理包。接受的值为 'bundle' 或 'external'。

--platform Jump to heading

要捆绑的平台。接受的值为 'browser' 或 'deno'。

--preload Jump to heading

在主模块之前执行的文件列表。

--sourcemap Jump to heading

生成源映射。接受的值为 'linked'、'inline' 或 'external'。

--watch Jump to heading

监听并根据更改重新构建。

信息

deno bundle 目前是一个实验性子命令,可能会有变动。

deno bundle [URL] 将输出一个单独的 JavaScript 文件供 Deno 使用,该文件包含指定输入的所有依赖项。例如

$ deno bundle https://deno.land/std@0.190.0/examples/colors.tsts colors.bundle.js
Bundle https://deno.land/std@0.190.0/examples/colors.ts
Download https://deno.land/std@0.190.0/examples/colors.ts
Download https://deno.land/std@0.190.0/fmt/colors.ts
Emit "colors.bundle.js" (9.83KB)

如果您省略输出文件,捆绑包将发送到 stdout

捆绑包可以像 Deno 中的任何其他模块一样运行

deno run colors.bundle.js

输出是一个自包含的 ES 模块,命令行上提供的主模块中的任何导出都将可用。例如,如果主模块看起来像这样

export { foo } from "./foo.js";

export const bar = "bar";

它可以像这样导入

import { bar, foo } from "./lib.bundle.js";

为 Web 打包 Jump to heading

deno bundle 的输出旨在供 Deno 使用,而不适用于 Web 浏览器或其他运行时。也就是说,根据输入,它可能在其他环境中运行。

如果您希望为 Web 打包,我们推荐其他解决方案,例如 esbuild

您找到所需内容了吗?

隐私政策