File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ {
2+ "name" : " nitro-playground" ,
3+ "version" : " 1.0.0" ,
4+ "type" : " module" ,
5+ "scripts" : {
6+ "build" : " vite build" ,
7+ "preview" : " vite preview" ,
8+ "dev" : " vite dev"
9+ },
10+ "devDependencies" : {
11+ "@preact/preset-vite" : " ^2.10.2" ,
12+ "@tailwindcss/vite" : " ^4.1.14" ,
13+ "nitro" : " npm:nitro-nightly" ,
14+ "tailwindcss" : " ^4.1.14" ,
15+ "vite" : " ^7.1.8"
16+ },
17+ "dependencies" : {
18+ "preact" : " ^10.27.2" ,
19+ "preact-render-to-string" : " ^6.6.2"
20+ }
21+ }
Original file line number Diff line number Diff line change 1+ import { useState } from "preact/hooks" ;
2+
3+ export function Counter ( ) {
4+ const [ count , setCount ] = useState ( 0 ) ;
5+ return (
6+ < button onClick = { ( ) => setCount ( ( c ) => c + 1 ) } > Count is { count } </ button >
7+ ) ;
8+ }
Original file line number Diff line number Diff line change 1+ import { hydrate } from "preact" ;
2+ import { Counter } from "./counter" ;
3+
4+ function main ( ) {
5+ hydrate ( < Counter /> , document . querySelector ( "#counter" ) ! ) ;
6+ }
7+
8+ main ( ) ;
Original file line number Diff line number Diff line change 1+ import "./styles.css" ;
2+ import { renderToReadableStream } from "preact-render-to-string/stream" ;
3+ import { Counter } from "./counter" ;
4+
5+ import type { } from "@hiogawa/vite-plugin-fullstack/types" ;
6+
7+ import clientAssets from "./entry-client?assets=client" ;
8+ import serverAssets from "./entry-server?assets=ssr" ;
9+
10+ export default {
11+ async fetch ( request : Request ) {
12+ const url = new URL ( request . url ) ;
13+ const htmlStream = renderToReadableStream ( < Root url = { url } /> ) ;
14+ return new Response ( htmlStream , {
15+ headers : { "Content-Type" : "text/html;charset=utf-8" } ,
16+ } ) ;
17+ } ,
18+ } ;
19+
20+ function Root ( props : { url : URL } ) {
21+ const assets = clientAssets . merge ( serverAssets ) ;
22+ return (
23+ < html lang = "en" >
24+ < head >
25+ < meta name = "viewport" content = "width=device-width, initial-scale=1.0" />
26+ < title > Vite Assets Example</ title >
27+ { assets . css . map ( ( attr ) => (
28+ < link key = { attr . href } rel = "stylesheet" { ...attr } />
29+ ) ) }
30+ { assets . js . map ( ( attr ) => (
31+ < link key = { attr . href } type = "modulepreload" { ...attr } />
32+ ) ) }
33+ < script type = "module" src = { assets . entry } />
34+ </ head >
35+ < body >
36+ < h1 className = "hero" > Vite Assets Example</ h1 >
37+ < p > URL: { props . url . href } </ p >
38+ < div id = "counter" >
39+ < Counter />
40+ </ div >
41+ </ body >
42+ </ html >
43+ ) ;
44+ }
Original file line number Diff line number Diff line change 1+ .hero {
2+ color : orange;
3+ }
4+
5+ button {
6+ background-color : lightskyblue;
7+ }
Original file line number Diff line number Diff line change 1+ {
2+ "compilerOptions" : {
3+ // Module resolution
4+ "target" : " ESNext" ,
5+ "module" : " ESNext" ,
6+ "moduleResolution" : " Bundler" ,
7+ "allowImportingTsExtensions" : true ,
8+
9+ // JSX
10+ "jsx" : " react-jsx" ,
11+ "jsxImportSource" : " preact" ,
12+
13+ // Core checks
14+ "strict" : true ,
15+ "noEmit" : true ,
16+ "skipLibCheck" : true ,
17+ "resolveJsonModule" : true ,
18+ "allowSyntheticDefaultImports" : true ,
19+
20+ // Additional safety
21+ "forceConsistentCasingInFileNames" : true ,
22+ "noImplicitReturns" : true ,
23+ "noFallthroughCasesInSwitch" : true ,
24+ "useUnknownInCatchVariables" : true ,
25+ "noUnusedLocals" : true ,
26+
27+ // Libs & paths
28+ "lib" : [" ESNext" , " DOM" ],
29+ "types" : [" vite/client" , " node" ],
30+ "baseUrl" : " ."
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ import { defineConfig } from "vite" ;
2+ import { nitro } from "nitro/vite" ;
3+ import preact from "@preact/preset-vite" ;
4+
5+ export default defineConfig ( {
6+ plugins : [ nitro ( ) , preact ( ) ] ,
7+ environments : {
8+ client : {
9+ build : {
10+ rollupOptions : {
11+ input : "./src/entry-client.tsx" ,
12+ } ,
13+ } ,
14+ } ,
15+ } ,
16+ } ) ;
Original file line number Diff line number Diff line change 7575 "@azure/static-web-apps-cli" : " ^2.0.7" ,
7676 "@cloudflare/workers-types" : " ^4.20251014.0" ,
7777 "@deno/types" : " ^0.0.1" ,
78+ "@hiogawa/vite-plugin-fullstack" : " 0.0.5" ,
7879 "@netlify/edge-functions" : " ^3.0.1" ,
7980 "@netlify/functions" : " ^5.0.1" ,
8081 "@rollup/plugin-alias" : " ^5.1.1" ,
You can’t perform that action at this time.
0 commit comments