mirror of
https://github.com/kou029w/_.git
synced 2025-01-31 06:18:07 +00:00
create wmr-ssg
This commit is contained in:
parent
70c68198c3
commit
254efe47b6
9 changed files with 132 additions and 0 deletions
3
wmr-ssg/.gitignore
vendored
Normal file
3
wmr-ssg/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
/.cache/
|
||||||
|
/dist/
|
||||||
|
/node_modules/
|
13
wmr-ssg/package.json
Normal file
13
wmr-ssg/package.json
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"devDependencies": {
|
||||||
|
"@exampledev/new.css": "^1.1.3",
|
||||||
|
"@wmrjs/directory-import": "^0.3.0",
|
||||||
|
"preact": "^10.5.15",
|
||||||
|
"preact-iso": "^2.3.0",
|
||||||
|
"wmr": "^3.7.2"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"dev": "wmr",
|
||||||
|
"build": "wmr build --prerender"
|
||||||
|
}
|
||||||
|
}
|
14
wmr-ssg/public/index.html
Normal file
14
wmr-ssg/public/index.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>wmr-ssg-example</title>
|
||||||
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="https://cdn.jsdelivr.net/npm/@exampledev/new.css/new.min.css"
|
||||||
|
/>
|
||||||
|
<script type="module" src="main.tsx"></script>
|
||||||
|
</head>
|
||||||
|
<body></body>
|
||||||
|
</html>
|
48
wmr-ssg/public/main.tsx
Normal file
48
wmr-ssg/public/main.tsx
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
import {
|
||||||
|
LocationProvider,
|
||||||
|
ErrorBoundary,
|
||||||
|
Router,
|
||||||
|
lazy,
|
||||||
|
hydrate,
|
||||||
|
prerender as ssr,
|
||||||
|
} from "preact-iso";
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
|
import pages from "dir:./pages";
|
||||||
|
|
||||||
|
const routes = (pages as string[]).map((name: string) => {
|
||||||
|
const filename = name.replace(/\.tsx$/, "");
|
||||||
|
const url = `/${filename.replace(/_index$/, "")}`;
|
||||||
|
const Route = lazy(() => import(`./pages/${filename}.tsx`));
|
||||||
|
|
||||||
|
console.log(url);
|
||||||
|
|
||||||
|
return { url, Route };
|
||||||
|
});
|
||||||
|
|
||||||
|
function App() {
|
||||||
|
return (
|
||||||
|
<LocationProvider>
|
||||||
|
<header>
|
||||||
|
<nav>
|
||||||
|
<a href="/">Home</a> / <a href="/hello">Hello</a>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
<ErrorBoundary>
|
||||||
|
<Router>
|
||||||
|
{routes.map(({ Route, url }) => (
|
||||||
|
<Route path={url} />
|
||||||
|
))}
|
||||||
|
</Router>
|
||||||
|
</ErrorBoundary>
|
||||||
|
</LocationProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function prerender() {
|
||||||
|
return await ssr(<App />);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
hydrate(<App />, document.body);
|
||||||
|
}
|
5
wmr-ssg/public/pages/_index.tsx
Normal file
5
wmr-ssg/public/pages/_index.tsx
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
export default () => (
|
||||||
|
<main>
|
||||||
|
<h1>ようこそ!</h1>
|
||||||
|
</main>
|
||||||
|
);
|
5
wmr-ssg/public/pages/hello.tsx
Normal file
5
wmr-ssg/public/pages/hello.tsx
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
export default () => (
|
||||||
|
<main>
|
||||||
|
<h1>Hello!</h1>
|
||||||
|
</main>
|
||||||
|
);
|
13
wmr-ssg/tsconfig.json
Normal file
13
wmr-ssg/tsconfig.json
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"noEmit": true,
|
||||||
|
"strict": true,
|
||||||
|
"target": "esnext",
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"lib": ["dom", "dom.iterable", "esnext"],
|
||||||
|
"jsx": "preserve",
|
||||||
|
"jsxImportSource": "preact"
|
||||||
|
},
|
||||||
|
"include": ["public"]
|
||||||
|
}
|
3
wmr-ssg/wmr.config.ts
Normal file
3
wmr-ssg/wmr.config.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
import directoryPlugin from "@wmrjs/directory-import";
|
||||||
|
|
||||||
|
export default directoryPlugin;
|
28
wmr-ssg/yarn.lock
Normal file
28
wmr-ssg/yarn.lock
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||||
|
# yarn lockfile v1
|
||||||
|
|
||||||
|
|
||||||
|
"@exampledev/new.css@^1.1.3":
|
||||||
|
version "1.1.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/@exampledev/new.css/-/new.css-1.1.3.tgz#fcc1f15629db8cd105ad2e8c649095ca10623007"
|
||||||
|
integrity sha512-qhbGfqBRwUlM6MCSaJdUfjq86opNCMvM+6kVvs6S0kYhy0V8dKbe4rDMIklEJGuMc5QH5OuPjdCReu9I0tim2w==
|
||||||
|
|
||||||
|
"@wmrjs/directory-import@^0.3.0":
|
||||||
|
version "0.3.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@wmrjs/directory-import/-/directory-import-0.3.0.tgz#cb04113d43e22fcfe4515de14c46643f675b0a3d"
|
||||||
|
integrity sha512-2Ga/v3/hDL8IOnwlvGax3fB/5+EeNT2JM/fGAFO6rtaiOWJ9GUI5TB+2Z3RRS8hYKEbP5PbEOuUMchObxDWeyA==
|
||||||
|
|
||||||
|
preact-iso@^2.3.0:
|
||||||
|
version "2.3.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/preact-iso/-/preact-iso-2.3.0.tgz#ab6c5de28df9e0f7a0589dd2175a83ba821f69ec"
|
||||||
|
integrity sha512-taJmRidbWrjHEhoVoxXS2Kvxa6X3jXSsTtD7rSYeJuxnPNr1ghCu1JUzCrRxmZwTUNWIqwUpNi+AJoLtvCPN7g==
|
||||||
|
|
||||||
|
preact@^10.5.15:
|
||||||
|
version "10.5.15"
|
||||||
|
resolved "https://registry.yarnpkg.com/preact/-/preact-10.5.15.tgz#6df94d8afecf3f9e10a742fd8c362ddab464225f"
|
||||||
|
integrity sha512-5chK29n6QcJc3m1lVrKQSQ+V7K1Gb8HeQY6FViQ5AxCAEGu3DaHffWNDkC9+miZgsLvbvU9rxbV1qinGHMHzqA==
|
||||||
|
|
||||||
|
wmr@^3.7.2:
|
||||||
|
version "3.7.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/wmr/-/wmr-3.7.2.tgz#3d6dfb771fafc0e2119d4502aaea26ecd5963c19"
|
||||||
|
integrity sha512-i+e/T8J067qP2pBgq6E2gaW9qMGK+D9eGue85YM0Vflc2UuzXBP3fSS5PzvyHEKuPHZWmcFBmZRs6DU9Lkr9og==
|
Loading…
Add table
Reference in a new issue