Vue server components. Take away your vnodes. Also works client to client
β οΈ This is a proof of concept.undefined
Vue Onigiri enables Vue Server Components by serializing and deserializing Vue component trees (VNodes). You can capture snapshots of Vue components either on the server or client side and reconstruct them on another client, allowing for server-side rendering patterns and component sharing between Vue applications.
# npm
npm install vue-onigiri
# yarn
yarn add vue-onigiri
# pnpm
pnpm add vue-onigiri
# bun
bun add vue-onigiri
undefinedSerializing a Component:undefined
import { serializeComponent } from "vue-onigiri/runtime/serialize";
import MyComponent from "./MyComponent.vue";
// Serialize a component to transferable data
const serializedData = await serializeComponent(MyComponent, {
message: "Hello from server!",
});
// Send this data to the client...
undefinedDeserializing and Rendering:undefined
import { renderOnigiri } from "vue-onigiri/runtime/deserialize";
import { createApp, h } from "vue";
// Receive serialized data from server
const app = createApp({
setup() {
return () => renderOnigiri(serializedData);
},
});
app.mount("#app");
Vue Onigiri provides Vite plugins for both client and server environments:
// vite.config.js
import { defineConfig } from "vite";
import { vueOnigiriPluginFactory } from "vue-onigiri";
const { client, server } = vueOnigiriPluginFactory({
includeClientChunks: ["**/*.vue"], // Components to include as client chunks
serverAssetsDir: "server-chunks",
clientAssetsDir: "client-chunks",
});
export default defineConfig({
plugins: [
// Use client() for client build, server() for server build
process.env.BUILD_TARGET === "server" ? server() : client(),
],
});
interface VSCOptions {
includeClientChunks: string[]; // Glob patterns for components to chunk
rootDir?: string; // Root directory (default: cwd)
vueServerOptions?: Options; // Vue plugin options for server
serverAssetsDir?: string; // Server chunks directory
clientAssetsDir?: string; // Client chunks directory
}
serializeComponent(component, props?, context?)Serializes a Vue component with optional props and SSR context.
import { serializeComponent } from "vue-onigiri/runtime/serialize";
const data = await serializeComponent(
MyComponent,
{ title: "Hello" }, // Props
{ url: "/current-page" }, // SSR Context
);
serializeApp(app, context?)Serializes an entire Vue application VNode.
import { serializeApp } from "vue-onigiri/runtime/serialize";
import { createApp } from "vue";
const app = createApp(RootComponent);
const data = await serializeApp(app, { url: "/current-page" });
renderOnigiri(data, importFn?)Renders serialized VNode data back into actual VNodes.
import { renderOnigiri } from "vue-onigiri/runtime/deserialize";
// Custom import function for loading components
// can be useful server side as client chunks are loaded by default
// made to be used by Nuxt
const customImportFn = (chunkPath) => import(chunkPath);
const vnode = renderOnigiri(serializedData, customImportFn);
Vue Onigiri handles different types of Vue components during serialization:
Server Side:
VNode Tree β Serialize β JSON Data
Client Side:
JSON Data β Deserialize β VNode Tree β Render
# Run all tests
pnpm test
# Run tests with coverage
pnpm test --coverage
# Run tests in watch mode
pnpm test --watch
# Run development playground
pnpm dev
corepack enablepnpm installpnpm dev# Build the library
pnpm build
# Run development server with playground
pnpm dev
# Run linting
pnpm lint
# Fix linting issues
pnpm lint:fix
# Run tests
pnpm test
# Run tests with type checking
pnpm test:types
# Release new version
pnpm release
π€ auto updated with automd
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.