LiveVue.SSR behaviour and two built-in implementations: LiveVue.SSR.NodeJS and LiveVue.SSR.ViteJS.
LiveVue.SSR
A behaviour for rendering Vue components server-side. This module defines the interface that SSR implementations must follow and provides the mainrender/3 function.
Configuration
To define a custom renderer, change the application config inconfig.exs:
render/3
Renders a Vue component server-side.The name of the Vue component to render.
A map of props to pass to the component. Keys can be strings or atoms.
A map of slots to pass to the component. Keys can be strings or atoms.
A render response with the following shape:
Telemetry
The module exposes a telemetry span for each render under the key[:live_vue, :ssr]. The metadata includes:
component- Component nameprops- Props passed to the componentslots- Slots passed to the component
LiveVue.SSR.NodeJS
Implements SSR by using a Node.js subprocess. This is the recommended approach for production deployments.How it works
Under the hood, it invokes therender function exposed by the server.js file. You can see how server.js is created by looking at the assets.deploy command and package.json build-server script.
Configuration
Add the NodeJS supervisor to yourapplication.ex:
config.exs:
render/3
Renders a Vue component using Node.js.The name of the Vue component to render.
Props to pass to the component.
Slots to pass to the component.
Returns the rendered HTML as a binary string.
server_path/0
Returns the path to the Node.js server directory.Returns the application’s
priv directory path.LiveVue.SSR.ViteJS
Implements SSR by making HTTP requests to a Vite development server. This is the recommended approach for development.How it works
Makes a POST request tohttp://{:vite_host}/ssr_render. The ssr_render endpoint is implemented as a Vite plugin.
Configuration
Add the LiveVue plugin to yourvite.config.js:
config/dev.exs:
render/3
Renders a Vue component using Vite’s dev server.The name of the Vue component to render.
Props to pass to the component.
Slots to pass to the component.
Returns the rendered HTML as a binary string, or an error tuple with a descriptive message.
- Connection failures (Vite not running)
- 500 errors with stack traces from Vite
- Unexpected HTTP status codes
vite_path/1
A handy utility for constructing paths relative to the Vite host.The path to append to the Vite host URL.
Returns the full URL by joining the configured Vite host with the provided path.