1
0
Fork 0
mirror of https://github.com/kou029w/_.git synced 2025-01-30 22:08:02 +00:00

preact → solid

This commit is contained in:
Nebel 2022-01-22 14:16:50 +00:00 committed by GitHub
parent 998590ba13
commit 7c47400823
7 changed files with 505 additions and 485 deletions

View file

@ -3,13 +3,10 @@
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"devDependencies": { "devDependencies": {
"@preact/preset-vite": "^2.1.3", "babel-preset-solid": "^1.3.2",
"@types/node": "^16.10.3", "vite": "^2.7.13",
"@types/react": "^17.0.28", "vite-plugin-solid": "^2.2.4",
"preact": "^10.5.15", "vite-plugin-ssr": "^0.3.46"
"preact-render-to-string": "^5.1.19",
"vite": "^2.6.7",
"vite-plugin-ssr": "^0.3.10"
}, },
"scripts": { "scripts": {
"build": "vite build && vite build --ssr && vite-plugin-ssr prerender" "build": "vite build && vite build --ssr && vite-plugin-ssr prerender"

View file

@ -1,10 +1,8 @@
import { hydrate as reactHydrate } from "preact"; import { hydrate as solidHydrate } from "solid-js/web";
import { getPage } from "vite-plugin-ssr/client"; import { getPage } from "vite-plugin-ssr/client";
import type { PageContextBuiltInClient } from "vite-plugin-ssr/types"; import type { PageContextBuiltInClient } from "vite-plugin-ssr/types";
export async function hydrate() { export async function hydrate() {
const pageContext = await getPage<PageContextBuiltInClient>(); const pageContext = await getPage<PageContextBuiltInClient>();
const { Page } = pageContext; solidHydrate(pageContext.Page, document.body);
reactHydrate(<Page />, document.body);
} }

View file

@ -0,0 +1,17 @@
import { renderToString } from "solid-js/web";
import { escapeInject, dangerouslySkipEscape } from "vite-plugin-ssr";
import type { PageContextBuiltIn } from "vite-plugin-ssr/types";
export async function render(pageContext: PageContextBuiltIn) {
const page = renderToString(pageContext.Page);
return escapeInject`<!DOCTYPE html>
<html>
<head>
<title>vite-ssg-example</title>
</head>
<body>
${dangerouslySkipEscape(page)}
</body>
</html>
`;
}

View file

@ -1,18 +0,0 @@
import renderToString from "preact-render-to-string";
import { escapeInject, dangerouslySkipEscape } from "vite-plugin-ssr";
import type { PageContextBuiltIn } from "vite-plugin-ssr/types";
export async function render(pageContext: PageContextBuiltIn) {
const html = renderToString(
<html>
<head>
<title>vite-ssg-example</title>
</head>
<body>
<pageContext.Page />
</body>
</html>
);
return escapeInject`<!DOCTYPE html>${dangerouslySkipEscape(html)}`;
}

View file

@ -8,7 +8,7 @@
"lib": ["dom", "dom.iterable", "esnext"], "lib": ["dom", "dom.iterable", "esnext"],
"types": ["vite/client"], "types": ["vite/client"],
"jsx": "preserve", "jsx": "preserve",
"jsxImportSource": "preact" "jsxImportSource": "solid-js"
}, },
"include": ["pages", "renderer"] "include": ["pages", "renderer"]
} }

View file

@ -1,7 +1,7 @@
import { defineConfig } from "vite"; import { defineConfig } from "vite";
import preact from "@preact/preset-vite"; import solid from "vite-plugin-solid";
import ssr from "vite-plugin-ssr/plugin"; import ssr from "vite-plugin-ssr/plugin";
export default defineConfig({ export default defineConfig({
plugins: [preact(), ssr()], plugins: [solid(), ssr()],
}); });

File diff suppressed because it is too large Load diff