Bundling

deno bundle [URL] will output a single JavaScript file, which includes all dependencies of the specified input. For example:

`

  1. > deno bundle https://deno.land/std@0.84.0/examples/colors.ts colors.bundle.jsBundle https://deno.land/std@0.84.0/examples/colors.tsDownload https://deno.land/std@0.84.0/examples/colors.tsDownload https://deno.land/std@0.84.0/fmt/colors.tsEmit "colors.bundle.js" (9.83KB)

`

If you omit the out file, the bundle will be sent to stdout.

The bundle can just be run as any other module in Deno would:

`

  1. deno run colors.bundle.js

`

The output is a self contained ES Module, where any exports from the main module supplied on the command line will be available. For example, if the main module looked something like this:

`

  1. export { foo } from "./foo.js";
  2. export const bar = "bar";

`

It could be imported like this:

`

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

`

Bundles can also be loaded in the web browser. The bundle is a self-contained ES module, and so the attribute of type must be set to "module". For example:

`

  1. <script type="module" src="website.bundle.js"></script>

`

Or you could import it into another ES module to consume:

`

  1. <script type="module"> import * as website from "website.bundle.js";</script>

`