Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Latest commit

 

History

History
75 lines (53 loc) · 2.04 KB

compiler.md

File metadata and controls

75 lines (53 loc) · 2.04 KB

Compiling Executables

deno compile [--output <OUT>] <SRC> will compile the script into a self-contained executable.

> deno compile https://examples.deno.land/hello-world.ts

If you omit the OUT parameter, the name of the executable file will be inferred.

Flags

As with deno install, the runtime flags used to execute the script must be specified at compilation time. This includes permission flags.

> deno compile --allow-read --allow-net https://deno.land/std/http/file_server.ts

Script arguments can be partially embedded.

> deno compile --allow-read --allow-net https://deno.land/std/http/file_server.ts -p 8080
> ./file_server --help

Dynamic Imports

By default, statically analyzable dynamic imports (imports that have the string literal within the import("...") call expression) will be included in the output.

// calculator.ts and its dependencies will be included in the binary
const calculator = await import("./calculator.ts");

But non-statically analyzable dynamic imports won't:

const specifier = condition ? "./calc.ts" : "./better_calc.ts";
const calculator = await import(specifier);

To include non-statically analyzable dynamic imports, specify an --include <path> flag.

deno compile --include calc.ts --include better_calc.ts main.ts

Workers

Similarly to non-statically analyzable dynamic imports, code for workers is not included in the compiled executable by default. You must use the --include <path> flag to include the worker code.

deno compile --include worker.ts main.ts

Cross Compilation

You can compile binaries for other platforms by adding the --target CLI flag. Deno currently supports compiling to Windows x64, macOS x64, macOS ARM and Linux x64. Use deno compile --help to list the full values for each compilation target.

Unavailable in executables