Deno Desktop apps
摘要
文档介绍了计划随 Deno 2.9 发布的 deno desktop。它可将从单个 TypeScript 文件到 Next.js 等完整 Web 项目打包为独立桌面应用,产物包含应用代码、Deno Runtime 和渲染引擎。其设计重点包括:默认使用系统 WebView 以减小体积,同时保留 Node / npm 生态兼容;可自动识别 Next.js、Astro、Remix、Nuxt、SvelteKit、Vite SSR 等框架并直接运行;前后端通过进程内绑定通信而非 IPC;支持单机跨平台构建(macOS、Windows、Linux);内置基于 bsdiff 的自动更新与回滚机制。文档还列出了后续章节内容,包括窗口管理、菜单、系统托盘、原生对话框、通知、DevTools、热更新、错误上报、分发与安装器,以及与 Electron、Tauri、Electrobun 等方案的对比。
荐读理由
单文件 Deno.serve() 就能编译出跨平台自含桌面二进制,配合 framework auto-detection 和 in-process bindings 能零改动落地 Next.js/Astro 等现有 Web 项目到桌面,避开 Electron 的巨大二进制和多平台缺失
原文
Hello, desktop
What's in this section
Desktop apps
View Page as MarkdownOpen the Markdown file in a new tabOpen in ClaudeAsk Claude about this pagellms.txtMachine-readable index of these docs for AI tools
deno desktop turns a Deno project (anything from a single TypeScript file to a Next.js app) into a self-contained desktop application. The output is a redistributable binary that bundles your code, the Deno runtime, and a web rendering engine into one bundle per platform.
Coming in Deno 2.9
deno desktop ships in Deno v2.9.0 and is not in a stable release yet. To try it now, run deno upgrade canary to install the canary build. The command, configuration keys, and TypeScript APIs may still change before the feature is stable.
Why deno desktop Jump to heading#
Web technology is the most widely-known UI toolkit in the world. Desktop apps built on web stacks (Electron, Tauri, Electrobun) take advantage of that, but each has tradeoffs you have to live with: huge binaries, missing platform support, no JavaScript ecosystem, no built-in update story, no framework integration.
deno desktop is opinionated about those tradeoffs:
Small by default, full Node compatibility. The default WebView backend uses the operating system's own webview for small binaries, and you still have the entire npm ecosystem available through Deno's Node compat layer. Opt into the bundled Chromium (CEF) backend when you need identical rendering across macOS, Windows, and Linux.
Framework auto-detection. Point
deno desktopat a Next.js, Astro, Fresh, Remix, Nuxt, SvelteKit, SolidStart, TanStack Start, or Vite SSR project and it runs: the production server in release mode, the dev server with hot reload under--hmr. No code changes are required to take an existing web project to the desktop.In-process bindings instead of IPC. Backend and UI communication goes through in-process channels, not socket-based IPC. Values are still encoded as they cross the call boundary, but there is no cross-process round-trip between your Deno code and the webview.
Cross-compile from one machine. The same machine can build for macOS, Windows, and Linux. Backends are downloaded as needed, not built locally.
Built-in binary-diff auto-update. Ship a single
latest.jsonmanifest and bsdiff patches; the runtime polls, applies, and rolls back automatically on failed launches.
Hello, desktop Jump to heading#
Create a one-file desktop app:
main.ts
Deno.serve(() =>
new Response("<h1>Hello, desktop</h1>", {
headers: { "content-type": "text/html" },
})
);
_
deno desktop main.ts
The compiled binary opens a window pointed at a local HTTP server bound to your Deno.serve() handler. Run it directly:
_
./main
.\main.exe
Deno.serve() automatically binds to the address the webview navigates to, so you do not need to pass a port or hostname. See HTTP serving for details.
What's in this section Jump to heading#
Configuration: the
desktopblock indeno.json.Backends: CEF, webview, raw; how to choose.
HTTP serving:
Deno.serve()integration and the serving model.Frameworks: Next.js, Astro, Fresh, Remix, Nuxt, SvelteKit, and others.
Windows:
Deno.BrowserWindowlifecycle, multiple windows, events.Bindings: calling Deno code from the webview via
bindings.<name>().Menus: application and context menus.
Tray and dock: system status icons and the macOS dock.
Dialogs:
prompt(),alert(),confirm()as native popups.Notifications: native OS notifications via the Web
NotificationAPI.Hot module replacement:
--hmrfor framework and non-framework apps.DevTools: unified DevTools attached to both the Deno runtime and the webview.
Auto-update:
Deno.autoUpdate(), manifests, bsdiff, rollback.Error reporting: capturing uncaught exceptions and panics.
Distribution: cross-compilation, output formats, installers.
Comparison: how
deno desktoprelates to Electron, Tauri, Electrobun, Dioxus.deno desktopCLI reference: the command, its flags, and thedeno.jsondesktopschema.
这条对你有帮助吗?