@amagaki/amagaki-engine-preact
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

amagaki-engine-preact

NPM Version TypeScript Style Guide

An Amagaki plugin for using Preact (TSX) for template rendering. Supports server-side rendering (SSR) and (optionally) hydration.

This engine can be used to bring React into an Amagaki project with minimal overhead, and you can choose whether to also use it on your site's frontend. Page modules can be created entirely using React components (via Preact) and integrate seamlessly with frontend components also built in React.

Usage

  1. Install the plugin. This plugin is meant to be used in conjunction with @amagaki/amagaki-plugin-page-builder.
npm install --save \ 
  @amagaki/amagaki-engine-preact \
  @amagaki/amagaki-plugin-page-builder
  1. Add to amagaki.ts.
import {PageBuilder} from '@amagaki/amagaki-plugin-page-builder';
import {Pod} from '@amagaki/amagaki';
import {PreactEnginePlugin} from '../src';

export default (pod: Pod) => {
  PreactEnginePlugin.register(pod);
  PageBuilder.register(pod, {
    partialPaths: {
      css: ['/dist/css/${partial.partial}/${partial.partial}.css'],
      js: ['/dist/js/partials/${partial.partial}/${partial.partial}.js'],
      view: ['/src/partials/${partial.partial}/${partial.partial}.tsx'],
    },
  });
};
  1. If your partial requires hydration:

    a. Add to your frontend's main.tsx.

    import {PartialHydrator} from '@amagaki/amagaki-engine-preact';
    
    // Import all partials that require hydration.
    import Hero from './partials/Hero';
    
    PartialHydrator.register({
      components: {
        'Hero': Hero,
      },
    });

    b. Ensure includeContext: true is supplied in YAML files for any partial that requires hydration.

    partials:
    - partial: Hero
      includeContext: true
      headline: Hello World!

Readme

Keywords

none

Package Sidebar

Install

npm i @amagaki/amagaki-engine-preact

Homepage

amagaki.dev

Weekly Downloads

240

Version

2.0.1

License

MIT

Unpacked Size

9.41 kB

Total Files

8

Last publish

Collaborators

  • jeremydw
  • zoramite