Renderer

Renderer plugins allow users to customize how Greenwood server renders (and prerenders) your project. By default, Greenwood just supports using (template) strings to return static HTML for the content and template of your server side routes. For example, using Lit SSR to render Lit Web Components server side.

API

Given that rendering Web Components on the server side often involves implementations needing to patch the NodeJS globals space, the Greenwood API for executing server rendered code will need to happen in a Worker thread. So at a high level, each implementation will need to provide a path to a worker script.

  • workerUrl (required) - URL to the location of the worker thread to use for SSR
  • prerender (optional) - If this custom renderer should be used to statically prerender pages too.
const greenwoodPluginMyCustomRenderer = (options = {}) => {
  return {
    type: 'renderer',
    name: 'plugin-renderer-custom',
    provider: () => {
      return {
        workerUrl: new URL('./my-ssr-route-worker.js', import.meta.url),
        prerender: options.prerender
      };
    }
  };
};

export {
  greenwoodPluginMyCustomRenderer
};

Example

As with Greenwood's default server rendering implementation, each worker is expected to implement the API of getBody, getTemplate, getFrontmatter. You can see how Greenwood implemented this for our Lit renderer Worker as a reference.