react-torch
Version:
A lib to server-side render with react.
128 lines (127 loc) • 3.77 kB
TypeScript
/// <reference types="node" />
/// <reference types="global" />
export declare const TORCH_DIR = ".torch";
export declare const TORCH_CLIENT_DIR = "client";
export declare const TORCH_SERVER_DIR = "server";
export declare const TORCH_PUBLIC_DIR = "public";
export declare const TORCH_PUBLIC_PATH = "__torch";
export declare const TORCH_SRC_DIR = "src";
export declare const TORCH_MIDDLEWARE_DIR = "middleware";
export declare const TORCH_MDLW_FILE_NAME = "middleware.js";
export declare const TORCH_DOCUMENT_FILE_NAME = "document.js";
export declare const TORCH_ROUTES_FILE_NAME = "routes.js";
export declare const TORCH_ASSETS_FILE_NAME = "assets.json";
export declare const TORCH_FAVICON_FILE_NAME = "favicon.ico";
export declare const TORCH_DOCUMENT_CONTAINER = "root";
export declare enum Env {
Development = "development",
Production = "production"
}
export declare enum Side {
Client = "client",
Server = "server"
}
export declare enum PreloadType {
Link = "link",
Inner = "inner"
}
export declare enum HistoryType {
Browser = "browser",
Hash = "hash"
}
import type { Server } from 'http';
import type { Express, Application } from 'express';
import type { Configuration } from 'webpack';
export declare type TorchConfig = {
host?: string;
port?: number;
dir?: string;
src?: string;
public?: string;
cdn?: string;
middleware?: string | false;
document?: string | false;
container?: string | false;
ssr?: boolean;
title?: string;
favicon?: string | boolean;
styleMode?: PreloadType;
createServer?: ServerCreater;
transformWebpackConfig?: WebpackConfigTransform;
installPolyfill?: PolyfillInstaller;
};
export declare type IntegralTorchConfig = {
host: string;
port: number;
dir: string;
src: string;
public: string;
cdn: string;
middleware: string | false;
document: string;
container: string;
ssr: boolean;
title: string;
favicon: string | false;
styleMode: PreloadType;
createServer: ServerCreater | false;
transformWebpackConfig: WebpackConfigTransform;
installPolyfill: PolyfillInstaller;
};
export declare type TinyContext = {
ssr: boolean;
env: Env;
};
export declare type PackContext = TinyContext & {
packSide: Side;
};
export declare type ClientContext = TinyContext & {
side: Side.Client;
};
export declare type ServerContext = TinyContext & {
side: Side.Server;
};
export declare type TorchData = {
context: Context;
container: string;
state: object;
};
export declare type Context = ClientContext | ServerContext;
export declare type Middleware = (app: Application, server: Server) => void;
export declare type Middlewares = {
assets?: Middleware;
} & Record<string, Middleware>;
export declare type StylePreload = {
type: PreloadType.Inner;
content: string;
} | {
type: PreloadType.Link;
href: string;
preload: boolean;
};
export declare type ScriptPreload = {
type: PreloadType.Inner;
content: string;
} | {
type: PreloadType.Link;
src: string;
};
export declare type ServerCreater = (config: IntegralTorchConfig) => Express;
export declare type PolyfillInstaller = (config: IntegralTorchConfig) => void;
export declare type WebpackConfigTransform = (config: Configuration, packContext: PackContext, torchConfig: IntegralTorchConfig) => Configuration;
export declare type ScriptOptions = {
dir?: string;
port?: string;
config?: string;
};
export declare type Assets = {
index: string;
vendor: string;
} & Record<string, string>;
export declare type RenderContext = {
url: string;
assets: Assets;
scripts: ScriptPreload[];
styles: StylePreload[];
others: Record<string, any>;
};