Show HN: Nectar,一个编译为 WebAssembly 的类 Rust React 框架
Show HN: Nectar, a Rust-like React that compiles to WebAssembly

原始链接: https://buildnectar.com

Nectar 是一款革命性的 Web 开发框架,它无需 JavaScript、npm 以及臃肿的 `node_modules`。通过将应用程序的逻辑、状态和渲染全部编译为单个 WebAssembly (WASM) 二进制文件,Nectar 为传统 Web 技术栈提供了一种高性能的替代方案。 主要特性包括: * **零依赖:** 一个 Rust 二进制文件即可管理所有事务,包括构建、代码检查和部署,将基础设施占用减少至 10 KB 的系统调用层。 * **细粒度性能:** Nectar 放弃了虚拟 DOM,转而采用 O(1) 响应式信号,确保仅更新必要的 DOM 节点。 * **编译时安全性:** 基于 Rust 严格的类型系统和借用检查器,Nectar 有助于在代码上线前发现并修复错误。 * **内置原语:** 路由、身份验证和数据库访问等常见的 Web 需求均作为核心语言特性存在,而非依赖外部库。 * **通用执行:** 同一个 WASM 二进制文件即可处理客户端交互和服务器端渲染 (SSR),从而实现向边缘环境的无缝部署。 Nectar 以精简、类型安全且极速的工作流程取代了现代 Web 开发中“依赖地狱”的现状,有效宣告了传统 JavaScript 工具链的过时。

**Nectar** 是一门全新的编程语言,旨在通过直接编译为 WebAssembly (WASM),在提供 React 式开发体验的同时实现卓越的性能。它通过自定义的信号驱动渲染层来最小化对 JavaScript 的依赖,能够以 O(1) 的时间复杂度更新 DOM 节点,从而无需虚拟 DOM (Virtual DOM) 或垃圾回收机制。 主要特性包括: * **工具链:** 提供单一二进制文件,集成了编译器、开发服务器、格式化工具、代码检查工具及语言服务器协议 (LSP)。 * **架构:** 借鉴 Rust 的借用检查机制以确保编译时安全,并针对常见的 Web 开发模式(如路由、身份验证、状态管理)提供了语言级关键字支持。 * **优化:** 支持细粒度的响应式系统,并采用双 DOM 编译方案以兼顾 SEO 和无障碍访问。 尽管该项目展现了巨大的性能潜力——将典型的 JS 开销从数百 KB 降低至约 10 KB 的桥接代码——但开发者强调,目前项目仍处于早期实验阶段。该项目目前采用 BSL 1.1 协议授权,且面临移动端兼容性及浏览器特定稳定性等早期技术障碍。开发者正积极寻求关键反馈,以评估其核心架构是否适用于实际生产环境。
相关文章

原文
Nectar — The Web Without JavaScript

Nectar compiles to WebAssembly. One language, one binary, zero dependencies. Your entire app — logic, state, rendering — runs in WASM. JavaScript is reduced to a 10 KB syscall layer.

Note: The Svelte demo may time out on first load with 10K products. Try refreshing if it appears blank.

Write less. Ship faster.

// package.json: 47 dependencies // node_modules: 1,247 packages import React, { useState } from 'react'; import ReactDOM from 'react-dom'; function Counter() { const [count, setCount] = useState(0); return ( <div> <p>{count}</p> <button onClick={() => setCount(c => c + 1)}> + </button> </div> ); }

// No package.json. No node_modules. // One file. Compiles to WASM. component Counter() { let mut count: i32 = 0; fn increment(&mut self) { self.count = self.count + 1; } render { <div> <p>{format("{}", self.count)}</p> <button on:click={self.increment}>"+"</button> </div> } }

Built different.

Single Binary Compiler

One Rust binary handles everything: compile, format, lint, test, dev server, LSP, package management, SSR. No toolchain to configure.

Fine-Grained Signals

O(1) updates per binding. No virtual DOM, no diffing, no reconciliation. When a signal changes, only the exact DOM node updates.

🔒

Compile-Time Safety

Rust-inspired borrow checker, type system, and exhaustive pattern matching. Catch bugs before they ship — not in production.

📦

Zero Dependencies

No npm, no node_modules, no webpack, no bundler. Your app compiles to a .wasm binary and a 3 KB runtime. That's it.

🌐

Built-In Keywords

component, store, router, page, form, auth, payment, upload, db, cache, agent — common web patterns are language primitives, not libraries.

🚀

SSR + Edge Deploy

The same WASM binary runs on the server via wasmtime. Built-in SSR, hydration, and deployment to 29 Cloud Run regions.

How Nectar works

Your .nectar source compiles to WebAssembly. The browser loads the .wasm and a 10 KB syscall layer. Everything else is WASM.

Source.nectar

CompilerRust

Output.wasm

RuntimeBrowser

JavaScript Runtime10 KB (DOM syscalls only)
Virtual DOMNone — command buffer
State ManagementWASM signals — O(1)
Borrow CheckerCompile-time safety
node_modulesZero. Deleted.
GC PausesNone — linear memory
XSS AttacksImpossible — no eval
AuthHttpOnly cookies by default

See it running.

10,000 products. Canvas rendering engine. Reactive signals. All running in WebAssembly. Side-by-side with Svelte 5.

Building something with Nectar?

Kicking the tires, want early access, or just have thoughts? Drop your email and I'll reach out. It's one person building this, so it comes straight to me.

联系我们 contact @ memedata.com