Skip to content

roxiness/tossr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tossr

Universal SPA to SSR

Render HTML from any SPA.

Install

npm i tossr

Usage example

const { tossr } = require('tossr')

const template = 'dist/index.html'
const script = 'dist/app.js'
const url = '/blog/ssr-is-fun'

const html = await tossr(template, script, url)

Related libraries

  • Spassr Small Express server with built in SSR
  • Spank Generate a static site from any SPA

API

Table of Contents

tossr

Renders an HTML page from a HTML template, an app bundle and a path

Parameters
  • template string Html template (or path to a HTML template).
  • script string Bundled JS app (or path to bundled bundle JS app).
  • url string Path to render. Ie. /blog/breathing-oxygen-linked-to-staying-alive
  • options Partial<Config>? Options

Returns Promise<string>

Config

Type: object

Properties
  • host string hostname to use while rendering. Defaults to http://jsdom.ssr
  • eventName string event to wait for before rendering app. Defaults to 'app-loaded'
  • beforeEval Eval Executed before script is evaluated.
  • afterEval Eval Executed after script is evaluated.
  • silent boolean Don't print timestamps
  • inlineDynamicImports boolean required for apps with dynamic imports
  • timeout number required for apps with dynamic imports
  • dev boolean disables caching of inlinedDynamicImports bundle
  • errorHandler function

Eval

Called before/after the app script is evaluated

Type: Function

Parameters

Party vector created by gstudioimagen - www.freepik.com