From 254efe47b6c4b8b80b4b64eb18bf7f026222a04d Mon Sep 17 00:00:00 2001 From: Kohei Watanabe Date: Wed, 13 Oct 2021 19:40:13 +0900 Subject: [PATCH] create wmr-ssg --- wmr-ssg/.gitignore | 3 +++ wmr-ssg/package.json | 13 +++++++++ wmr-ssg/public/index.html | 14 ++++++++++ wmr-ssg/public/main.tsx | 48 +++++++++++++++++++++++++++++++++ wmr-ssg/public/pages/_index.tsx | 5 ++++ wmr-ssg/public/pages/hello.tsx | 5 ++++ wmr-ssg/tsconfig.json | 13 +++++++++ wmr-ssg/wmr.config.ts | 3 +++ wmr-ssg/yarn.lock | 28 +++++++++++++++++++ 9 files changed, 132 insertions(+) create mode 100644 wmr-ssg/.gitignore create mode 100644 wmr-ssg/package.json create mode 100644 wmr-ssg/public/index.html create mode 100644 wmr-ssg/public/main.tsx create mode 100644 wmr-ssg/public/pages/_index.tsx create mode 100644 wmr-ssg/public/pages/hello.tsx create mode 100644 wmr-ssg/tsconfig.json create mode 100644 wmr-ssg/wmr.config.ts create mode 100644 wmr-ssg/yarn.lock diff --git a/wmr-ssg/.gitignore b/wmr-ssg/.gitignore new file mode 100644 index 0000000..ca36288 --- /dev/null +++ b/wmr-ssg/.gitignore @@ -0,0 +1,3 @@ +/.cache/ +/dist/ +/node_modules/ diff --git a/wmr-ssg/package.json b/wmr-ssg/package.json new file mode 100644 index 0000000..f911acf --- /dev/null +++ b/wmr-ssg/package.json @@ -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" + } +} diff --git a/wmr-ssg/public/index.html b/wmr-ssg/public/index.html new file mode 100644 index 0000000..3e323c3 --- /dev/null +++ b/wmr-ssg/public/index.html @@ -0,0 +1,14 @@ + + + + + wmr-ssg-example + + + + + + diff --git a/wmr-ssg/public/main.tsx b/wmr-ssg/public/main.tsx new file mode 100644 index 0000000..5af5c1e --- /dev/null +++ b/wmr-ssg/public/main.tsx @@ -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 ( + +
+ +
+ + + {routes.map(({ Route, url }) => ( + + ))} + + +
+ ); +} + +export async function prerender() { + return await ssr(); +} + +if (typeof window !== "undefined") { + hydrate(, document.body); +} diff --git a/wmr-ssg/public/pages/_index.tsx b/wmr-ssg/public/pages/_index.tsx new file mode 100644 index 0000000..6c605c9 --- /dev/null +++ b/wmr-ssg/public/pages/_index.tsx @@ -0,0 +1,5 @@ +export default () => ( +
+

ようこそ!

+
+); diff --git a/wmr-ssg/public/pages/hello.tsx b/wmr-ssg/public/pages/hello.tsx new file mode 100644 index 0000000..e62abea --- /dev/null +++ b/wmr-ssg/public/pages/hello.tsx @@ -0,0 +1,5 @@ +export default () => ( +
+

Hello!

+
+); diff --git a/wmr-ssg/tsconfig.json b/wmr-ssg/tsconfig.json new file mode 100644 index 0000000..9556252 --- /dev/null +++ b/wmr-ssg/tsconfig.json @@ -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"] +} diff --git a/wmr-ssg/wmr.config.ts b/wmr-ssg/wmr.config.ts new file mode 100644 index 0000000..7f897fd --- /dev/null +++ b/wmr-ssg/wmr.config.ts @@ -0,0 +1,3 @@ +import directoryPlugin from "@wmrjs/directory-import"; + +export default directoryPlugin; diff --git a/wmr-ssg/yarn.lock b/wmr-ssg/yarn.lock new file mode 100644 index 0000000..27dba7c --- /dev/null +++ b/wmr-ssg/yarn.lock @@ -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==