In Deno v1.6, the compile command was added. It outputs a module and its dependencies as a single binary. It uses the current directory’s name.

See the v1.6 blog post.

See the discussion thread.

Write

Write to same directory. This output file will use the name of the current directory. No extension.

$ deno compile --unstable index.ts

Write to a custom path.

deno compile --unstable -o build/bundle.js index.ts

Order of galgs

Note flags must come before arguments.

Using deno compile index.ts --unstable gives an error and using -o at the end gets ignored.

This contrasts with other commands. For example, this is suggested by the CLI for bundling and watching and it does work:

USAGE:
    deno bundle <source_file> --unstable --watch

URL

Use a URL instead of a path to a local module.

$ deno compile --unstable https://deno.land/std@0.79.0/examples/cat.ts
$ deno compile --unstable https://deno.land/std@0.79.0/http/file_server.ts
Check https://deno.land/std@0.79.0/http/file_server.ts
Bundle https://deno.land/std@0.79.0/http/file_server.ts
Compile https://deno.land/std@0.79.0/http/file_server.ts
Emit file_server

$ ./file_server
HTTP server listening on http://0.0.0.0:4507/