Skip to content

Commit e36f8d5

Browse files
authored
Wouter magazin (#553)
* Experimental SSR playground. * Update. * Fix useSearch in SSR regression. * Improve the fix. * One more test. * Fix the app. * Build in memory. * Serve static and add favicon. * React 19. * Tailwind and wouter-commerce. * Format. * Wouter commerce. * Handler redirects on the server-side. * Add to cart using history state. * Use actual products with images. * Implement custom status codes. * Support dynamic port. * Move navbar to components. * Use `useSearchParams` hook. * Sourdough becomes magazin. * Dynamic titles via react helmet. * Fix type error. * Remove console.log * Rewrite the copy.
1 parent 715223a commit e36f8d5

32 files changed

Lines changed: 1181 additions & 33 deletions

CLAUDE.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
description: Use Bun instead of Node.js, npm, pnpm, or vite.
3+
globs: "*.ts, *.tsx, *.html, *.css, *.js, *.jsx, package.json"
4+
alwaysApply: false
5+
---
6+
7+
Default to using Bun instead of Node.js.
8+
9+
- Use `bun <file>` instead of `node <file>` or `ts-node <file>`
10+
- Use `bun test` instead of `jest` or `vitest`
11+
- Use `bun build <file.html|file.ts|file.css>` instead of `webpack` or `esbuild`
12+
- Use `bun install` instead of `npm install` or `yarn install` or `pnpm install`
13+
- Use `bun run <script>` instead of `npm run <script>` or `yarn run <script>` or `pnpm run <script>`
14+
- Bun automatically loads .env, so don't use dotenv.
15+
16+
## APIs
17+
18+
- `Bun.serve()` supports WebSockets, HTTPS, and routes. Don't use `express`.
19+
- `bun:sqlite` for SQLite. Don't use `better-sqlite3`.
20+
- `Bun.redis` for Redis. Don't use `ioredis`.
21+
- `Bun.sql` for Postgres. Don't use `pg` or `postgres.js`.
22+
- `WebSocket` is built-in. Don't use `ws`.
23+
- Prefer `Bun.file` over `node:fs`'s readFile/writeFile
24+
- Bun.$`ls` instead of execa.
25+
26+
## Testing
27+
28+
Use `bun test` to run tests.
29+
30+
```ts#index.test.ts
31+
import { test, expect } from "bun:test";
32+
33+
test("hello world", () => {
34+
expect(1).toBe(1);
35+
});
36+
```
37+
38+
## Frontend
39+
40+
Use HTML imports with `Bun.serve()`. Don't use `vite`. HTML imports fully support React, CSS, Tailwind.
41+
42+
Server:
43+
44+
```ts#index.ts
45+
import index from "./index.html"
46+
47+
Bun.serve({
48+
routes: {
49+
"/": index,
50+
"/api/users/:id": {
51+
GET: (req) => {
52+
return new Response(JSON.stringify({ id: req.params.id }));
53+
},
54+
},
55+
},
56+
// optional websocket support
57+
websocket: {
58+
open: (ws) => {
59+
ws.send("Hello, world!");
60+
},
61+
message: (ws, message) => {
62+
ws.send(message);
63+
},
64+
close: (ws) => {
65+
// handle close
66+
}
67+
},
68+
development: {
69+
hmr: true,
70+
console: true,
71+
}
72+
})
73+
```
74+
75+
HTML files can import .tsx, .jsx or .js files directly and Bun's bundler will transpile & bundle automatically. `<link>` tags can point to stylesheets and Bun's CSS bundler will bundle.
76+
77+
```html#index.html
78+
<html>
79+
<body>
80+
<h1>Hello, world!</h1>
81+
<script type="module" src="./frontend.tsx"></script>
82+
</body>
83+
</html>
84+
```
85+
86+
With the following `frontend.tsx`:
87+
88+
```tsx#frontend.tsx
89+
import React from "react";
90+
91+
// import .css files directly and it works
92+
import './index.css';
93+
94+
import { createRoot } from "react-dom/client";
95+
96+
const root = createRoot(document.body);
97+
98+
export default function Frontend() {
99+
return <h1>Hello, world!</h1>;
100+
}
101+
102+
root.render(<Frontend />);
103+
```
104+
105+
Then, run index.ts
106+
107+
```sh
108+
bun --hot ./index.ts
109+
```
110+
111+
For more information, read the Bun API docs in `node_modules/bun-types/docs/**.md`.

bun.lock

Lines changed: 67 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"description": "A minimalistic routing for React and Preact. Monorepo package.",
55
"type": "module",
66
"workspaces": [
7-
"packages/wouter",
8-
"packages/wouter-preact"
7+
"packages/*"
98
],
109
"scripts": {
1110
"fix:p": "prettier --write \"./**/*.(js|ts){x,}\"",
@@ -139,8 +138,8 @@
139138
"@testing-library/jest-dom": "^6.1.4",
140139
"@testing-library/react": "^16.3.0",
141140
"@types/bun": "1.3.3",
142-
"@types/react": "^18.2.0",
143-
"@types/react-dom": "^18.2.0",
141+
"@types/react": "^19",
142+
"@types/react-dom": "^19",
144143
"copyfiles": "^2.4.1",
145144
"eslint": "^7.19.0",
146145
"eslint-plugin-react-hooks": "^4.6.2",
@@ -150,9 +149,9 @@
150149
"preact": "^10.23.2",
151150
"preact-render-to-string": "^6.5.9",
152151
"prettier": "^2.4.1",
153-
"react": "^18.2.0",
154-
"react-dom": "^18.2.0",
152+
"react": "^19",
153+
"react-dom": "^19",
155154
"size-limit": "^11.2.0",
156155
"typescript": "^5.8.0"
157156
}
158-
}
157+
}

packages/magazin/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# dependencies (bun install)
2+
node_modules
3+
4+
# output
5+
out
6+
dist
7+
*.tgz
8+
9+
# code coverage
10+
coverage
11+
*.lcov
12+
13+
# logs
14+
logs
15+
_.log
16+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
17+
18+
# dotenv environment variable files
19+
.env
20+
.env.development.local
21+
.env.test.local
22+
.env.production.local
23+
.env.local
24+
25+
# caches
26+
.eslintcache
27+
.cache
28+
*.tsbuildinfo
29+
30+
# IntelliJ based IDEs
31+
.idea
32+
33+
# Finder (MacOS) folder config
34+
.DS_Store

0 commit comments

Comments
 (0)