Deno 桌面版
Deno Desktop

原始链接: https://docs.deno.com/runtime/desktop/

从 Deno v2.9.0 开始,**deno desktop** 允许开发者将任何 Deno 项目(从简单的脚本到 Next.js 或 Astro 等复杂的 Web 框架)打包为独立、可分发的桌面应用程序。 与 Electron 或 Tauri 等现有解决方案不同,*deno desktop* 专注于减小二进制文件体积、提供完整的 Node.js 兼容性以及无缝的开发体验。其主要功能包括: * **框架无关性:** 自动检测主流 Web 框架,无需修改代码。 * **高性能:** 使用进程内绑定(in-process bindings)代替 IPC,实现更快的后端到 UI 通信。 * **内置工具:** 提供跨平台编译、原生系统集成(菜单、托盘、通知、对话框)以及稳健的二进制差分自动更新系统。 * **灵活的后端:** 默认使用操作系统原生 WebView 以获得紧凑的二进制体积,并提供可选的集成 Chromium (CEF) 后端以实现一致的跨平台渲染。 *deno desktop* 目前可在 canary 版本中使用,它通过利用 Deno 运行时和通用的 Web 生态系统简化了桌面开发。虽然 API 在正式发布前可能会有所变动,但它为构建现代跨平台应用程序提供了一个强大且具有独特见解的替代方案。

Hacker News 关于“Deno Desktop”的讨论反映了对该项目的不同看法。支持者认为它有望成为 Electron 或 Tauri 的轻量级跨平台替代方案,并对其占用空间小以及 Deno 安全模型的优势表示赞赏。 然而,相关讨论也引发了批评性的辩论: * **安全与权限:** 用户对 Deno 的权限处理机制表现出兴趣,并特别指出权限是在编译时植入二进制文件的,一些用户认为这对终端用户来说应该更加透明。 * **关于“原生”的辩论:** 一些评论者批评在桌面应用中使用 Web 技术,认为它们无法复刻原生操作系统的 UI/UX 模式,且并非真正的“UI 工具包”。 * **未来展望:** 有人建议桌面浏览器最终应提供标准化的沙盒 WebView,这可能使当前的桌面 Web 框架变得多余。 总的来说,尽管社区认为 Deno Desktop 是一个巧妙且有前景的工具,但在能否提供与传统桌面开发相媲美的真正原生用户体验方面,它仍面临质疑。
相关文章

原文

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

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 desktop at 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.json manifest and bsdiff patches; the runtime polls, applies, and rolls back automatically on failed launches.

Hello, desktop

Create a one-file desktop app:

main.ts

Deno.serve(() =>
  new Response("<h1>Hello, desktop</h1>", {
    headers: { "content-type": "text/html" },
  })
);

The compiled binary opens a window pointed at a local HTTP server bound to your Deno.serve() handler. Run it directly:

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

联系我们 contact @ memedata.com