Bundling and Compiling Code

Learn to bundle Deno code into a single file and compile it.

Bundle command

When we get into production, we want our servers to be as fast as possible. Previously, we learned that one of the slowest parts of Deno is TypeScript parsing. When we write TypeScript code, we don’t want to sacrifice time parsing it every time a new instance of the server starts up. At the same time, as we write clean, separate modules, we don’t want to ship them separately into the production environment.

This is why Deno provides a feature that allows us to bundle code into a single file.

When we presented Deno, we elected bundling code as an exciting feature for many reasons. This feature has enormous potential, and we will explore this in more detail later. But since we’re exploring the CLI here, we’ll get to know the appropriate command.

It’s called bundle, and it bundles code into a single, self-contained ES module. Bundled code that doesn’t depend on the Deno namespace can also run in the browser with <script type="module"> and in Node.js.

Let’s use it to build our get-current-time.js script:

Get hands-on with 1400+ tech skills courses.