Installation

def deps do
  [{:phoenix_vapor, "~> 0.6"}]
end

PhoenixVapor brings Vize, which compiles Vue, and QuickBEAM, which runs JavaScript on the server: for Reactive mode and the full runtime, for macros and package components while compiling, and for the few expressions only JavaScript can evaluate. Volt compiles PhoenixVapor's own TypeScript at build time. All of them are precompiled NIFs, so there is no Node.js to install.

Choosing a mode

Start with the simplest mode that does what you need:

  1. ~VUE templates: Vue syntax in place of HEEx. Assigns, events, and state stay ordinary LiveView.
  2. Server-only .vue files: the same, with the template in a single-file component.
  3. Reactive: a .vue file whose ref() state, computeds, and handlers run on the server. The LiveView module can be empty.
  4. Hybrid: the server owns the data passed as props, and Vue in the browser owns UI state. Interactions such as filtering and sorting never reach the server.
  5. Full runtime: render Vue component libraries on the server with the complete Vue runtime.

use PhoenixVapor, file: "X.vue" picks the mode from the file: a <script setup> with ref() is hybrid, anything else is server-only. Pass runtime: :reactive or runtime: :full to choose those.

Browser setup

Templates and server-only .vue files need no browser changes. Hybrid components, and direct DOM patching for Reactive mode, use modules PhoenixVapor ships as TypeScript. With Volt, resolve them from deps:

# config/config.exs
config :volt,
  resolve_dirs: ["node_modules", "deps"]

For a path or umbrella dependency, which isn't under deps/, add plugins: [PhoenixVapor.Volt] instead; it resolves the imports from wherever Mix put PhoenixVapor.

Then, in assets/js/app.js:

import { patchLiveSocket } from "phoenix_vapor"
import { getHybridHooks } from "phoenix_vapor/hybrid"
import * as Contacts from "./hybrid/Contacts.hybrid.js"

const liveSocket = new LiveSocket("/live", Socket, {
  hooks: { ...getHybridHooks({ Contacts }) }
})

patchLiveSocket(liveSocket)
liveSocket.connect()
  • getHybridHooks registers the PhoenixVaporHybrid hook for the hybrid components you pass. Each hybrid LiveView compiles its component to assets/js/hybrid/<Name>.hybrid.js.
  • patchLiveSocket writes value-only diffs for Reactive-mode renders straight to the DOM, skipping LiveView's re-render and morphdom pass. It is optional.

The hybrid client is a standard Vue 3 component, so install vue (3.5 or later) in your assets (mix npm.install vue).

Configuration

Reactive mode and the full runtime start a QuickBEAM runtime per LiveView. In production, share a pool of lightweight contexts instead:

# In your application's supervision tree
{QuickBEAM.ContextPool, name: MyApp.JSPool, size: 4}

# config/config.exs
config :phoenix_vapor, pool: MyApp.JSPool

Example app

examples/demo is a Phoenix app with every mode, including hybrid components built with Reka UI.