@joist/ssr
TypeScript icon, indicating that this package has built-in type declarations

3.9.1 • Public • Published

SSR (Experimental)

Render ShadowDOM on thee server with Declarative Shadow DOM. Parses HTML and recursively inserts user defined templates. The most important part of this would be the template loader. A template loader is an object that defines how the applicator will get the string values for both the html and the css. (css is optional).

import { Applicator. NoopTemplateCache, FileSysTemplateLoader } from '@joist/ssr';

// Define a template caching strategy and a template loader
const applicator = new Applicator(
  new NoopTemplateCache(),
  new FileSysTemplateLoader(
    (tag) => `elements/${tag}/${tag}.html`,
    (tag) => `elements/${tag}/${tag}.css`
  )
);

// Apply to a document and provide a list of elements to search for
applicator.apply(document, [])

Vite

import { Applicator. NoopTemplateCache, FileSysTemplateLoader } from '@joist/ssr';
import { defineConfig } from 'vite';

const applicator = new Applicator(
  new NoopTemplateCache(),
  new FileSysTemplateLoader(
    (tag) => `elements/${tag}/${tag}.html`,
    (tag) => `elements/${tag}/${tag}.css`
  )
);

export default defineConfig({
  plugins: [
    {
      transformIndexHtml: {
        enforce: "pre",
        transform(html) {
          return applicator.apply(html, ['my-element', 'my-dropdown']);
        }
      }
    }
  ],
});

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @joist/ssr

    Weekly Downloads

    41

    Version

    3.9.1

    License

    MIT

    Unpacked Size

    27.8 kB

    Total Files

    37

    Last publish

    Collaborators

    • deebloo