Skip to main content
The deno compile command compiles a Deno script into a self-contained executable that can run without the Deno CLI installed.

Usage

deno compile [OPTIONS] <SOURCE_FILE>

Basic Examples

# Compile a script
deno compile main.ts

# Compile with custom output name
deno compile --output myapp main.ts

# Compile with permissions
deno compile --allow-net --allow-read main.ts

# Cross-compile for different platform
deno compile --target x86_64-unknown-linux-gnu main.ts

Output Options

--output
string
Set the output file name
# Custom output name
deno compile --output myserver server.ts

# Output to specific directory
deno compile --output ./dist/myapp main.ts

# Directory path (infers name from script)
deno compile --output ./dist/ main.ts

Cross-compilation

--target
string
Compile for a specific target platform
# Linux
deno compile --target x86_64-unknown-linux-gnu main.ts

# macOS (Intel)
deno compile --target x86_64-apple-darwin main.ts

# macOS (Apple Silicon)
deno compile --target aarch64-apple-darwin main.ts

# Windows
deno compile --target x86_64-pc-windows-msvc main.ts

Including Files

--include
string
Include additional files in the compiled output
# Include configuration files
deno compile --include config.json,data/ main.ts

# Include templates
deno compile --include templates/ server.ts
--exclude
string
Exclude specific files or patterns
deno compile --exclude test/,*.test.ts main.ts

Executable Options

--no-terminal
boolean
Compile as a GUI application (Windows only)
deno compile --no-terminal --output myapp.exe main.ts
--icon
string
Set a custom icon for the executable (Windows only)
deno compile --icon icon.ico --output myapp.exe main.ts

Advanced Options

--eszip
boolean
Output an .eszip file instead of an executable
deno compile --eszip main.ts
# Creates main.eszip

Permission Flags

All permissions must be specified at compile time:
# Network access
deno compile --allow-net main.ts

# File system access
deno compile --allow-read --allow-write main.ts

# Subprocess execution
deno compile --allow-run main.ts

# Multiple permissions
deno compile --allow-net --allow-read --allow-env main.ts

Configuration

--config
string
Load configuration from a file
deno compile --config deno.json main.ts
--import-map
string
Load import map file
deno compile --import-map import_map.json main.ts
--node-modules-dir
boolean
Create a node_modules directory for npm packages
deno compile --node-modules-dir main.ts

Examples

Simple CLI Tool

// cli.ts
const name = Deno.args[0] ?? "World";
console.log(`Hello, ${name}!`);
# Compile
deno compile --output hello cli.ts

# Run the executable
./hello
./hello Deno

Web Server

// server.ts
Deno.serve({ port: 8000 }, () => {
  return new Response("Hello, World!");
});
# Compile with network permission
deno compile --allow-net --output server server.ts

# Run the server
./server

File Processing Tool

// process.ts
const inputFile = Deno.args[0];
const content = await Deno.readTextFile(inputFile);
const processed = content.toUpperCase();
await Deno.writeTextFile("output.txt", processed);
# Compile with file permissions
deno compile --allow-read --allow-write --output process process.ts

# Run
./process input.txt

Cross-Platform Compilation

# Build for all major platforms
deno compile --target x86_64-unknown-linux-gnu --output myapp-linux main.ts
deno compile --target x86_64-apple-darwin --output myapp-macos main.ts
deno compile --target x86_64-pc-windows-msvc --output myapp-windows main.ts

Including Assets

// app.ts
const template = await Deno.readTextFile("./templates/index.html");
const config = JSON.parse(await Deno.readTextFile("./config.json"));

Deno.serve(() => {
  return new Response(template, {
    headers: { "content-type": "text/html" },
  });
});
# Include templates and config
deno compile \
  --allow-net \
  --allow-read \
  --include templates/,config.json \
  --output webapp \
  app.ts

NPM Package Compilation

// npm-app.ts
import express from "npm:express@4";

const app = express();
app.get("/", (req, res) => res.send("Hello from Express!"));
app.listen(3000);
# Compile with npm packages
deno compile --allow-net --allow-read --allow-env --output express-app npm-app.ts

Platform-Specific Notes

Windows

  • Executables automatically get .exe extension
  • Use --no-terminal for GUI applications
  • Use --icon to set custom icon

macOS

  • Executables may need to be signed for distribution
  • Use chmod +x to make executable if needed
  • Different targets for Intel (x86_64) and Apple Silicon (aarch64)

Linux

  • Executables are created without extension
  • May need to mark as executable: chmod +x myapp
  • Works on most distributions

Size Optimization

Compiled executables include the Deno runtime, so they are typically 40-90 MB. Future optimizations may reduce this size.

Build docs developers (and LLMs) love