Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs/issue 149 clarify renderer plugin prerendering usage and options #152

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/pages/docs/reference/plugins-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,16 @@ export function myCopyPlugin() {

## Renderer

Renderer plugins allow users to customize how Greenwood server renders (and prerenders) your project. By default, Greenwood supports using [**WCC** or (template) strings](/docs/pages/server-rendering/) to return static HTML for the content and template of your server side routes. With this plugin for example, you can use [Lit's SSR](https://github.com/lit/lit/tree/main/packages/labs/ssr) to render your Lit Web Components on the server side instead. (but don't do that one specifically, we already have [a plugin](/docs/plugins/lit-ssr/) for Lit 😊)
Renderer plugins allow users to customize how Greenwood server renders (and prerenders) your project. By default, Greenwood supports using [**WCC** or (template) strings](/docs/pages/server-rendering/) to return static HTML for the content and template of your server side routes. For example, you can use [Lit's SSR capabilities](https://github.com/lit/lit/tree/main/packages/labs/ssr) to render your Lit Web Components on the server side instead. (but don't do that one specifically, we already have [a plugin](/docs/plugins/lit-ssr/) for Lit 😊)

> Note: Only **one** renderer plugin can be used at a time.

### API

This plugin expects to be given a path to a module that exports a function to execute the SSR content of a page by being given its HTML and related scripts. For local development Greenwood will run this in a `Worker` thread for live reloading, and use it standalone for production bundling and serving.

<!-- eslint-disable no-unused-vars -->

```js
const greenwoodPluginMyCustomRenderer = (options = {}) => {
return {
Expand All @@ -264,7 +268,6 @@ const greenwoodPluginMyCustomRenderer = (options = {}) => {
provider: () => {
return {
executeModuleUrl: new URL("./execute-route-module.js", import.meta.url),
prerender: options.prerender,
};
},
};
Expand All @@ -273,13 +276,14 @@ const greenwoodPluginMyCustomRenderer = (options = {}) => {
export { greenwoodPluginMyCustomRenderer };
```

<!-- eslint-enable no-unused-vars -->

#### Options

This plugin type supports the following options:

- **executeModuleUrl** (recommended) - `URL` to the location of a file with the SSR rendering implementation
- **customUrl** - `URL` to a file that has a `default export` of a function for handling the _prerendering_ lifecyle of a Greenwood build, and running the provided callback function
- **prerender** (optional) - Flag can be used to indicate if this custom renderer should be used to statically [prerender](/docs/reference/configuration/#prerender) pages too.

### Examples

Expand Down