@harlem/plugin-ssr

The official server-side rendering plugin for Harlem

Usage no npm install needed!

<script type="module">
  import harlemPluginSsr from 'https://cdn.skypack.dev/@harlem/plugin-ssr';
</script>

README

Harlem Server-Side Rendering Plugin

npm

This is the official plugin for using Harlem in a Vue SSR application.

Installation

Before installing the ssr plugin make sure you have installed @harlem/core.

yarn add @harlem/plugin-ssr
# or
npm install @harlem/plugin-ssr

Usage

Server

Create an instance of the plugin and register it with Harlem on the server:

import App from './app.vue';

import harlem from '@harlem/core';

import {
    createServerSSRPlugin
} from '@harlem/plugin-ssr';

createSSRApp(App)
    .use(harlem, {
        plugins: [
            createServerSSRPlugin()
        ]
    });

Generate the bridging script block and insert it into the server-rendered content:

import {
    renderToString
} from '@vue/server-renderer';

import {
    getBridgingScriptBlock
} from '@harlem/plugin-ssr';

let output = await renderToString(app);
output += getBridgingScriptBlock();

Client

Create an instance of the plugin and register it with Harlem on the client:

import App from './app.vue';

import harlem from '@harlem/core';

import {
    createClientSSRPlugin
} from '@harlem/plugin-ssr';

createApp(App)
    .use(harlem, {
        plugins: [
            createClientSSRPlugin()
        ]
    });

Warning

Types that are not support by JSON serialisation will not be transferred from server to client. See the MDN documentation on JSON serialisation for more information: MDN docs