Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions examples/vite-assets/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "nitro-playground",
"version": "1.0.0",
"type": "module",
"scripts": {
"build": "vite build",
"preview": "vite preview",
"dev": "vite dev"
},
"devDependencies": {
"@preact/preset-vite": "^2.10.2",
"@tailwindcss/vite": "^4.1.14",
"nitro": "npm:nitro-nightly",
"tailwindcss": "^4.1.14",
"vite": "^7.1.8"
},
"dependencies": {
"preact": "^10.27.2",
"preact-render-to-string": "^6.6.2"
}
}
8 changes: 8 additions & 0 deletions examples/vite-assets/src/counter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useState } from "preact/hooks";

export function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount((c) => c + 1)}>Count is {count}</button>
);
}
8 changes: 8 additions & 0 deletions examples/vite-assets/src/entry-client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { hydrate } from "preact";
import { Counter } from "./counter";

function main() {
hydrate(<Counter />, document.querySelector("#counter")!);
}

main();
44 changes: 44 additions & 0 deletions examples/vite-assets/src/entry-server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import "./styles.css";
import { renderToReadableStream } from "preact-render-to-string/stream";
import { Counter } from "./counter";

import type {} from "@hiogawa/vite-plugin-fullstack/types";

import clientAssets from "./entry-client?assets=client";
import serverAssets from "./entry-server?assets=ssr";

export default {
async fetch(request: Request) {
const url = new URL(request.url);
const htmlStream = renderToReadableStream(<Root url={url} />);
return new Response(htmlStream, {
headers: { "Content-Type": "text/html;charset=utf-8" },
});
},
};

function Root(props: { url: URL }) {
const assets = clientAssets.merge(serverAssets);
return (
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite Assets Example</title>
{assets.css.map((attr) => (
<link key={attr.href} rel="stylesheet" {...attr} />
))}
{assets.js.map((attr) => (
<link key={attr.href} type="modulepreload" {...attr} />
))}
<script type="module" src={assets.entry} />
</head>
<body>
<h1 className="hero">Vite Assets Example</h1>
<p>URL: {props.url.href}</p>
<div id="counter">
<Counter />
</div>
</body>
</html>
);
}
7 changes: 7 additions & 0 deletions examples/vite-assets/src/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.hero {
color: orange;
}

button {
background-color: lightskyblue;
}
32 changes: 32 additions & 0 deletions examples/vite-assets/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"compilerOptions": {
// Module resolution
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"allowImportingTsExtensions": true,

// JSX
"jsx": "react-jsx",
"jsxImportSource": "preact",

// Core checks
"strict": true,
"noEmit": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,

// Additional safety
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"useUnknownInCatchVariables": true,
"noUnusedLocals": true,

// Libs & paths
"lib": ["ESNext", "DOM"],
"types": ["vite/client", "node"],
"baseUrl": "."
}
}
16 changes: 16 additions & 0 deletions examples/vite-assets/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from "vite";
import { nitro } from "nitro/vite";
import preact from "@preact/preset-vite";

export default defineConfig({
plugins: [nitro(), preact()],
environments: {
client: {
build: {
rollupOptions: {
input: "./src/entry-client.tsx",
},
},
},
},
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"@azure/static-web-apps-cli": "^2.0.7",
"@cloudflare/workers-types": "^4.20251014.0",
"@deno/types": "^0.0.1",
"@hiogawa/vite-plugin-fullstack": "0.0.5",
"@netlify/edge-functions": "^3.0.1",
"@netlify/functions": "^5.0.1",
"@rollup/plugin-alias": "^5.1.1",
Expand Down
Loading
Loading