mirror of
https://github.com/kou029w/_.git
synced 2025-01-30 22:08:02 +00:00
preact → solid
This commit is contained in:
parent
998590ba13
commit
7c47400823
7 changed files with 505 additions and 485 deletions
|
@ -3,13 +3,10 @@
|
|||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"@preact/preset-vite": "^2.1.3",
|
||||
"@types/node": "^16.10.3",
|
||||
"@types/react": "^17.0.28",
|
||||
"preact": "^10.5.15",
|
||||
"preact-render-to-string": "^5.1.19",
|
||||
"vite": "^2.6.7",
|
||||
"vite-plugin-ssr": "^0.3.10"
|
||||
"babel-preset-solid": "^1.3.2",
|
||||
"vite": "^2.7.13",
|
||||
"vite-plugin-solid": "^2.2.4",
|
||||
"vite-plugin-ssr": "^0.3.46"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "vite build && vite build --ssr && vite-plugin-ssr prerender"
|
||||
|
|
|
@ -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 type { PageContextBuiltInClient } from "vite-plugin-ssr/types";
|
||||
|
||||
export async function hydrate() {
|
||||
const pageContext = await getPage<PageContextBuiltInClient>();
|
||||
const { Page } = pageContext;
|
||||
|
||||
reactHydrate(<Page />, document.body);
|
||||
solidHydrate(pageContext.Page, document.body);
|
||||
}
|
17
vite-ssg/renderer/_default.page.server.ts
Normal file
17
vite-ssg/renderer/_default.page.server.ts
Normal 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>
|
||||
`;
|
||||
}
|
|
@ -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)}`;
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"types": ["vite/client"],
|
||||
"jsx": "preserve",
|
||||
"jsxImportSource": "preact"
|
||||
"jsxImportSource": "solid-js"
|
||||
},
|
||||
"include": ["pages", "renderer"]
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { defineConfig } from "vite";
|
||||
import preact from "@preact/preset-vite";
|
||||
import solid from "vite-plugin-solid";
|
||||
import ssr from "vite-plugin-ssr/plugin";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [preact(), ssr()],
|
||||
plugins: [solid(), ssr()],
|
||||
});
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue