Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/deno/cli/js/deno.ts>bundle

A modern runtime for JavaScript and TypeScript.
Go to Latest
function bundle
import { bundle } from "https://deno.land/x/deno@v0.30.0/cli/js/deno.ts";

Takes a root module name, and optionally a record set of sources. Resolves with a single JavaScript string that is like the output of a deno bundle command. If just a root name is provided, the modules will be resolved as if the root module had been passed on the command line.

If sources are passed, all modules will be resolved out of this object, where the key is the module name and the value is the content. The extension of the module name will be used to determine the media type of the module.

 const [ maybeDiagnostics1, output1 ] = await Deno.bundle("foo.ts");

 const [ maybeDiagnostics2, output2 ] = await Deno.bundle("/foo.ts", {
   "/foo.ts": `export * from "./bar.ts";`,
   "/bar.ts": `export const bar = "bar";`
 });

Parameters

rootName: string

The root name of the module which will be used as the "starting point". If no sources is specified, Deno will resolve the module externally as if the rootName had been specified on the command line.

optional
sources: Record<string, string>

An optional key/value map of sources to be used when resolving modules, where the key is the module name, and the value is the source content. The extension of the key will determine the media type of the file when processing. If supplied, Deno will not attempt to resolve any modules externally.

optional
options: CompilerOptions

An optional object of options to send to the compiler. This is a subset of ts.CompilerOptions which can be supported by Deno.

Returns

Promise<[Diagnostic | undefined, string]>