Use solidstart as a static site generator together with Clouldflare Pages functions.
Deployed on Cloudflare Pages at https://create-solid-ssg.pages.dev/
Clone this repo and modify the project name in wrangler.toml and package.json.
pnpm install
pnpm dev
to start the solidstart (vinxi) dev serverpnpm build
to build the solidstart site (vinxi)pnpm preview
to preview the static site together with the functionpnpm ship
to deploy the static site to Cloudflare Pages
Tip
This project uses SolidStart to generate a static site, and Clouldflare Pages functions for server-side logic.
For SolidStart SSR, use the Solid
framework starter in npm create cloudflare
which installs the cloudflare-pages
preset
and generates _worker.js
.
pnpm create solid
say yes toIs this a SolidStart project?
, then chooseBasic
pnpm install wrangler
- add/modify files as below
"scripts": {
"dev": "vinxi dev",
"build": "vinxi build",
"preview": "pnpm run build && wrangler pages dev",
"ship": "pnpm run build && wrangler pages deploy"
},
#:schema node_modules/wrangler/config-schema.json
name = "create-solid-ssg"
compatibility_date = "2024-12-30"
compatibility_flags = ["nodejs_compat"]
pages_build_output_dir = ".output/public"
import { defineConfig } from '@solidjs/start/config';
// https://docs.solidjs.com/solid-start/building-your-application/route-prerendering
export default defineConfig({
server: {
preset: 'static',
prerender: {
crawlLinks: true,
ignore: ['/helloworld'],
},
},
});
// https://developers.cloudflare.com/pages/functions/get-started/#create-a-function
// https://developers.cloudflare.com/pages/functions/api-reference/#eventcontext
// https://developers.cloudflare.com/workers/runtime-apis/request/#incomingrequestcfproperties
export function onRequest(context) {
return new Response(`Hello from ${context.request.cf.city}!
The date is ${new Date().toDateString()}
The time is ${new Date().toLocaleTimeString()}`);
}
import { MetaProvider, Title } from '@solidjs/meta';
import { Router } from '@solidjs/router';
import { FileRoutes } from '@solidjs/start/router';
import { Suspense } from 'solid-js';
import './app.css';
export default function App() {
return (
<Router
root={(props) => (
<MetaProvider>
<Title>SolidStart - Basic</Title>
<a href="/">Index</a>
<a href="/about">About</a>
<a href="/helloworld" target="_self">
helloworld function
</a>
<Suspense>{props.children}</Suspense>
</MetaProvider>
)}
>
<FileRoutes />
</Router>
);
}
- https://discord.com/channels/722131463138705510/843551011825909760/1272458017983696897
- https://discord.com/channels/722131463138705510/1276808191228903456/1276814750499602495