Skip to content

hyf0/libvue-rs

Repository files navigation

libvue_compiler_sfc

Compile the Vue template compiler (@vue/compiler-dom) to native code using Static Hermes, making it callable from Rust without a JavaScript runtime.

Prerequisites

  • pnpm - Node.js package manager
  • just - Command runner
  • Ninja - Build system (for compiling Hermes)
  • CMake - Build configuration
  • Rust - For building the Rust library

Installing just

# macOS
brew install just

# Linux
cargo install just

# Windows (via cargo)
cargo install just

Quick Start

# Clone the repository
git clone <repo-url>
cd libvue_compiler_sfc

# Set up everything (install deps, build Hermes)
just setup

# Build the Rust library
just build

# Run the demo
just run

Available Commands

Run just to see all available commands:

Command Description
just setup Install dependencies, init submodules, build Hermes
just build Build the Rust project (release mode)
just run Run the demo binary
just bench Run all benchmarks
just bench-native Run Static Hermes benchmark
just bench-node Run Node.js V8 benchmark
just clean Clean build artifacts

How It Works

  1. Bundle: Vue compiler is bundled into a single JS file using Rolldown
  2. Compile: Static Hermes compiles the JS to native code (.o file)
  3. Link: Rust links against the compiled object and Hermes runtime
  4. Call: Rust code can call compile_template() directly

See CLAUDE.md for detailed architecture documentation.

API

use libvue_compiler_sfc::Compiler;

fn main() {
    let compiler = Compiler::new().expect("Failed to create compiler");
    // compile_template(source, filename, scope_id, is_scoped, script_bindings)
    let result = compiler
        .compile_template("<div>{{ msg }}</div>", "App.vue", "scope-id", false, None)
        .unwrap();
    println!("{}", result.code());
}

Benchmarks

Compare native compilation vs Node.js V8:

just bench

License

ISC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors