On this page
打包器(已弃用)
Command line usage
deno bundle [OPTIONS]
deno bundle
was removed in Deno 2.
See the Deno 1.x to 2.x Migration Guide for migration instructions: https://docs.deno.com/runtime/manual/advanced/migrate_deprecations
deno bundle [URL]
将输出一个供 Deno 使用的单个 JavaScript 文件,其中包含指定输入的所有依赖项。例如:
$ deno bundle https://deno.land/std@0.190.0/examples/colors.tsts colors.bundle.js
打包 https://deno.land/std@0.190.0/examples/colors.ts
下载 https://deno.land/std@0.190.0/examples/colors.ts
下载 https://deno.land/std@0.190.0/fmt/colors.ts
输出 "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 进行打包,我们推荐使用其他解决方案,例如 esbuild。