fix(plugin/twind): load configuration as module (#705)

This commit loads the Twind configuration as an actual module rather
than evaluating it on the server and then serializing. This allows usage
of unserializable plugin functions.

Co-authored-by: Elias Sjögreen <eliassjogreen1@gmail.com>
This commit is contained in:
Luca Casonato
2022-09-07 00:44:46 +02:00
committed by GitHub
co-authored by Elias Sjögreen
parent 8e9658cae5
commit 1b3c9f2569
7 changed files with 30 additions and 54 deletions
+5 -37
View File
@@ -1,40 +1,11 @@
import { JSX, options as preactOptions, VNode } from "preact";
import {
Configuration,
DarkMode,
setup as twSetup,
Sheet,
ThemeConfiguration,
tw,
} from "twind";
import { Configuration, setup as twSetup, Sheet, tw } from "twind";
export const STYLE_ELEMENT_ID = "__FRSH_TWIND";
export interface Options {
/**
* Determines the dark mode strategy (default: `"media"`).
*/
darkMode?: DarkMode;
/**
* The twind theme to use.
*/
theme?: ThemeConfiguration;
/**
* ```js
* {
* ':new-variant': '& .selector',
* }
* ```
*/
variants?: Record<string, string>;
/**
* Configure wether the class names should be emitted "as is", or if they
* should be hashed.
*/
hash?: boolean;
export interface Options extends Omit<Configuration, "mode" | "sheet"> {
/** The import.meta.url of the module defining these options. */
selfURL: string;
}
declare module "preact" {
@@ -48,12 +19,9 @@ declare module "preact" {
export function setup(options: Options, sheet: Sheet) {
const config: Configuration = {
darkMode: options.darkMode,
hash: options.hash,
...options,
mode: "silent",
sheet,
variants: options.variants,
theme: options.theme,
};
twSetup(config);