@evjs/create-app 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/basic-csr/package.json +1 -1
- package/templates/basic-fns-ecma/README.md +28 -0
- package/templates/basic-fns-ecma/index.html +11 -0
- package/templates/basic-fns-ecma/package.json +24 -0
- package/templates/basic-fns-ecma/server.entry.mjs +40 -0
- package/templates/basic-fns-ecma/src/api/messages.server.ts +33 -0
- package/templates/basic-fns-ecma/src/main.tsx +15 -0
- package/templates/basic-fns-ecma/src/pages/__root.tsx +19 -0
- package/templates/basic-fns-ecma/src/pages/home.tsx +76 -0
- package/templates/basic-fns-ecma/swMock.entry.js +85 -0
- package/templates/basic-fns-ecma/tsconfig.json +17 -0
- package/templates/basic-plugins/README.md +20 -0
- package/templates/basic-plugins/ev.config.ts +56 -0
- package/templates/basic-plugins/index.html +11 -0
- package/templates/basic-plugins/package.json +25 -0
- package/templates/basic-plugins/src/main.tsx +15 -0
- package/templates/basic-plugins/src/pages/__root.tsx +13 -0
- package/templates/basic-plugins/src/pages/home.tsx +24 -0
- package/templates/basic-plugins/tsconfig.json +18 -0
- package/templates/basic-server-fns/package.json +1 -1
- package/templates/basic-server-fns/src/main.tsx +4 -1
- package/templates/basic-server-fns/src/pages/__root.tsx +15 -0
- package/templates/basic-server-fns/src/{routes.tsx → pages/home.tsx} +3 -27
- package/templates/basic-server-routes/package.json +1 -1
- package/templates/basic-server-routes/src/main.tsx +4 -1
- package/templates/basic-server-routes/src/pages/__root.tsx +15 -0
- package/templates/basic-server-routes/src/{routes.tsx → pages/home.tsx} +3 -24
- package/templates/complex-routing/package.json +1 -1
- package/templates/configured-server-fns/package.json +1 -1
- package/templates/configured-server-fns/src/main.tsx +4 -1
- package/templates/configured-server-fns/src/pages/__root.tsx +20 -0
- package/templates/configured-server-fns/src/{routes.tsx → pages/home.tsx} +3 -30
- package/templates/server-fns-query/README.md +24 -0
- package/templates/server-fns-query/index.html +11 -0
- package/templates/server-fns-query/package.json +23 -0
- package/templates/server-fns-query/src/api/posts.server.ts +29 -0
- package/templates/server-fns-query/src/api/users.server.ts +49 -0
- package/templates/server-fns-query/src/main.tsx +21 -0
- package/templates/server-fns-query/src/pages/__root.tsx +22 -0
- package/templates/server-fns-query/src/pages/home.tsx +123 -0
- package/templates/server-fns-query/src/pages/search.tsx +64 -0
- package/templates/server-fns-query/src/pages/user.tsx +39 -0
- package/templates/server-fns-query/tsconfig.json +17 -0
- package/templates/sqlite-server-fns/README.md +26 -0
- package/templates/sqlite-server-fns/index.html +11 -0
- package/templates/sqlite-server-fns/package.json +23 -0
- package/templates/sqlite-server-fns/src/api/db.server.ts +174 -0
- package/templates/sqlite-server-fns/src/main.tsx +15 -0
- package/templates/sqlite-server-fns/src/pages/__root.tsx +35 -0
- package/templates/sqlite-server-fns/src/pages/home.tsx +271 -0
- package/templates/sqlite-server-fns/tsconfig.json +17 -0
- package/templates/trpc-server-fns/README.md +23 -0
- package/templates/trpc-server-fns/index.html +11 -0
- package/templates/trpc-server-fns/package.json +26 -0
- package/templates/trpc-server-fns/src/api/trpc.server.ts +33 -0
- package/templates/trpc-server-fns/src/main.tsx +15 -0
- package/templates/trpc-server-fns/src/pages/__root.tsx +32 -0
- package/templates/trpc-server-fns/src/pages/home.tsx +110 -0
- package/templates/trpc-server-fns/src/trpc.ts +16 -0
- package/templates/trpc-server-fns/tsconfig.json +17 -0
- package/templates/websocket-fns/README.md +25 -0
- package/templates/websocket-fns/index.html +11 -0
- package/templates/websocket-fns/package.json +25 -0
- package/templates/websocket-fns/src/api/users.server.ts +31 -0
- package/templates/websocket-fns/src/main.tsx +15 -0
- package/templates/websocket-fns/src/pages/__root.tsx +15 -0
- package/templates/websocket-fns/src/pages/home.tsx +152 -0
- package/templates/websocket-fns/tsconfig.json +17 -0
- package/templates/with-tailwind/package.json +1 -1
package/package.json
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# basic-fns-ecma
|
|
2
|
+
|
|
3
|
+
Server functions with the ECMA/Fetch adapter — works on Deno, Bun, and edge runtimes.
|
|
4
|
+
|
|
5
|
+
## Run
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm run dev -w example-basic-fns-ecma
|
|
9
|
+
|
|
10
|
+
# Production
|
|
11
|
+
npm run build -w example-basic-fns-ecma
|
|
12
|
+
npm run start -w example-basic-fns-ecma
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Key Files
|
|
16
|
+
|
|
17
|
+
| File | Purpose |
|
|
18
|
+
|------|---------|
|
|
19
|
+
| `src/main.tsx` | App bootstrap |
|
|
20
|
+
| `src/routes.tsx` | Routes + components |
|
|
21
|
+
| `src/api/messages.server.ts` | Server functions |
|
|
22
|
+
| `ev.config.ts` | Uses `@evjs/server/ecma` runtime |
|
|
23
|
+
|
|
24
|
+
## What It Demonstrates
|
|
25
|
+
|
|
26
|
+
- `createFetchHandler` from `@evjs/server/ecma`
|
|
27
|
+
- Portable server bundle (no Node.js-specific APIs)
|
|
28
|
+
- Custom runtime configuration via `ev.config.ts`
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "example-basic-fns-ecma",
|
|
3
|
+
"version": "0.0.19",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "npx ev dev",
|
|
7
|
+
"build": "npx ev build",
|
|
8
|
+
"start": "node dist/server/start.mjs",
|
|
9
|
+
"check-types": "tsc --noEmit"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"react": "^19.2.4",
|
|
13
|
+
"react-dom": "^19.2.4"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@evjs/cli": "*",
|
|
17
|
+
"@evjs/client": "*",
|
|
18
|
+
"@evjs/ev": "*",
|
|
19
|
+
"@evjs/server": "*",
|
|
20
|
+
"@types/react": "^19.1.8",
|
|
21
|
+
"@types/react-dom": "^19.1.8",
|
|
22
|
+
"typescript": "^6.0.2"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ECMA runtime adapter entry point.
|
|
3
|
+
*
|
|
4
|
+
* Loads the server bundle (which registers server functions via the runtime),
|
|
5
|
+
* creates a Hono app, and exports a standard fetch handler.
|
|
6
|
+
*
|
|
7
|
+
* Works in any Fetch API-compatible runtime:
|
|
8
|
+
* - Deno: `deno serve start.mjs`
|
|
9
|
+
* - Bun: `bun run start.mjs`
|
|
10
|
+
* - Edge runtimes: deploy as-is
|
|
11
|
+
* - Node.js 18+: use with @hono/node-server
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { readFileSync } from "node:fs";
|
|
15
|
+
import { createRequire } from "node:module";
|
|
16
|
+
|
|
17
|
+
const require = createRequire(import.meta.url);
|
|
18
|
+
|
|
19
|
+
// Read server manifest to find the entry bundle
|
|
20
|
+
const manifest = JSON.parse(
|
|
21
|
+
readFileSync(new URL("./manifest.json", import.meta.url), "utf-8"),
|
|
22
|
+
);
|
|
23
|
+
const bundle = require(`./server/${manifest.server.entry}`);
|
|
24
|
+
const app = bundle.createApp();
|
|
25
|
+
|
|
26
|
+
// Export via ECMA adapter — compatible with Deno, Bun, Workers
|
|
27
|
+
const { createFetchHandler } = require("@evjs/server/ecma");
|
|
28
|
+
const handler = createFetchHandler(app);
|
|
29
|
+
export default handler;
|
|
30
|
+
|
|
31
|
+
// For Node.js, start the server:
|
|
32
|
+
if (typeof process !== "undefined" && process.argv[1]?.endsWith("start.mjs")) {
|
|
33
|
+
const { serve } = await import("@hono/node-server");
|
|
34
|
+
const port = Number(process.env.PORT) || 3001;
|
|
35
|
+
serve({ fetch: app.fetch, port }, (info) => {
|
|
36
|
+
console.log(
|
|
37
|
+
`ECMA runtime server listening on http://localhost:${info.port}`,
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
|
|
3
|
+
/** Simulated message store. */
|
|
4
|
+
const messages: { id: string; text: string; timestamp: string }[] = [
|
|
5
|
+
{
|
|
6
|
+
id: "1",
|
|
7
|
+
text: "Hello from the ECMA runtime!",
|
|
8
|
+
timestamp: new Date().toISOString(),
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
id: "2",
|
|
12
|
+
text: "This server runs on any Fetch-compatible runtime.",
|
|
13
|
+
timestamp: new Date().toISOString(),
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
/** Get all messages. */
|
|
18
|
+
export async function getMessages() {
|
|
19
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
20
|
+
return messages;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Post a new message. */
|
|
24
|
+
export async function postMessage(text: string) {
|
|
25
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
26
|
+
const msg = {
|
|
27
|
+
id: String(messages.length + 1),
|
|
28
|
+
text,
|
|
29
|
+
timestamp: new Date().toISOString(),
|
|
30
|
+
};
|
|
31
|
+
messages.push(msg);
|
|
32
|
+
return msg;
|
|
33
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createApp } from "@evjs/client";
|
|
2
|
+
import { rootRoute } from "./pages/__root";
|
|
3
|
+
import { messagesRoute } from "./pages/home";
|
|
4
|
+
|
|
5
|
+
const routeTree = rootRoute.addChildren([messagesRoute]);
|
|
6
|
+
|
|
7
|
+
const app = createApp({ routeTree });
|
|
8
|
+
|
|
9
|
+
declare module "@tanstack/react-router" {
|
|
10
|
+
interface Register {
|
|
11
|
+
router: typeof app.router;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
app.render("#app");
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createRootRoute, Link, Outlet } from "@evjs/client";
|
|
2
|
+
|
|
3
|
+
function Root() {
|
|
4
|
+
return (
|
|
5
|
+
<div style={{ fontFamily: "system-ui, sans-serif", padding: "1rem" }}>
|
|
6
|
+
<h1>ECMA Runtime Example</h1>
|
|
7
|
+
<p style={{ color: "#666" }}>
|
|
8
|
+
Server bundle is environment-agnostic — works in Node.js, Deno, Bun, any
|
|
9
|
+
Fetch-compatible runtime.
|
|
10
|
+
</p>
|
|
11
|
+
<nav style={{ display: "flex", gap: "1rem", marginBottom: "1rem" }}>
|
|
12
|
+
<Link to="/">Messages</Link>
|
|
13
|
+
</nav>
|
|
14
|
+
<Outlet />
|
|
15
|
+
</div>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const rootRoute = createRootRoute({ component: Root });
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { createRoute } from "@evjs/client";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { getMessages, postMessage } from "../api/messages.server";
|
|
4
|
+
import { rootRoute } from "./__root";
|
|
5
|
+
|
|
6
|
+
function MessagesPage() {
|
|
7
|
+
const [text, setText] = useState("");
|
|
8
|
+
const [messages, setMessages] = useState<
|
|
9
|
+
{ id: string; text: string; timestamp: string }[]
|
|
10
|
+
>([]);
|
|
11
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
let mounted = true;
|
|
15
|
+
getMessages()
|
|
16
|
+
.then((data) => {
|
|
17
|
+
if (mounted) {
|
|
18
|
+
setMessages(data);
|
|
19
|
+
setIsLoading(false);
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
.catch((err) => {
|
|
23
|
+
console.error(err);
|
|
24
|
+
if (mounted) setIsLoading(false);
|
|
25
|
+
});
|
|
26
|
+
return () => {
|
|
27
|
+
mounted = false;
|
|
28
|
+
};
|
|
29
|
+
}, []);
|
|
30
|
+
|
|
31
|
+
async function handlePost(e: { preventDefault: () => void }) {
|
|
32
|
+
e.preventDefault();
|
|
33
|
+
if (!text) return;
|
|
34
|
+
try {
|
|
35
|
+
await postMessage(text);
|
|
36
|
+
setText("");
|
|
37
|
+
const data = await getMessages();
|
|
38
|
+
setMessages(data);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
console.error(err);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (isLoading) return <p>Loading messages from server…</p>;
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div>
|
|
48
|
+
<h2>Messages (via server functions)</h2>
|
|
49
|
+
<ul>
|
|
50
|
+
{messages.map((m) => (
|
|
51
|
+
<li key={m.id}>
|
|
52
|
+
<strong>{m.text}</strong>
|
|
53
|
+
<br />
|
|
54
|
+
<small style={{ color: "#999" }}>{m.timestamp}</small>
|
|
55
|
+
</li>
|
|
56
|
+
))}
|
|
57
|
+
</ul>
|
|
58
|
+
|
|
59
|
+
<h3>Post a Message</h3>
|
|
60
|
+
<form onSubmit={handlePost} style={{ display: "flex", gap: "0.5rem" }}>
|
|
61
|
+
<input
|
|
62
|
+
placeholder="Message"
|
|
63
|
+
value={text}
|
|
64
|
+
onChange={(e) => setText(e.target.value)}
|
|
65
|
+
/>
|
|
66
|
+
<button type="submit">Send</button>
|
|
67
|
+
</form>
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const messagesRoute = createRoute({
|
|
73
|
+
getParentRoute: () => rootRoute,
|
|
74
|
+
path: "/",
|
|
75
|
+
component: MessagesPage,
|
|
76
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service Worker adapter — runs server functions in the browser.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors server.entry.mjs but for the Service Worker environment.
|
|
5
|
+
* Intercepts /api/* requests (matching the default rpcEndpoint) and
|
|
6
|
+
* handles them locally via Hono. Update the path prefix below if
|
|
7
|
+
* using a custom rpcEndpoint.
|
|
8
|
+
*
|
|
9
|
+
* When running in Node.js (no native SW APIs), mock implementations
|
|
10
|
+
* are provided so the entry can be tested outside a browser.
|
|
11
|
+
*/
|
|
12
|
+
import { readFileSync } from "node:fs";
|
|
13
|
+
import { createRequire } from "node:module";
|
|
14
|
+
|
|
15
|
+
// ── Mock Service Worker APIs for Node.js testing ──
|
|
16
|
+
|
|
17
|
+
if (typeof self === "undefined") {
|
|
18
|
+
const listeners = {};
|
|
19
|
+
globalThis.self = /** @type {any} */ ({
|
|
20
|
+
addEventListener(type, handler) {
|
|
21
|
+
if (!listeners[type]) {
|
|
22
|
+
listeners[type] = [];
|
|
23
|
+
}
|
|
24
|
+
listeners[type].push(handler);
|
|
25
|
+
},
|
|
26
|
+
__listeners: listeners,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (typeof FetchEvent === "undefined") {
|
|
31
|
+
globalThis.FetchEvent = class FetchEvent extends Event {
|
|
32
|
+
/** @type {Request} */
|
|
33
|
+
request;
|
|
34
|
+
/** @type {Promise<Response> | Response | undefined} */
|
|
35
|
+
_response;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {string} type
|
|
39
|
+
* @param {{ request: Request }} init
|
|
40
|
+
*/
|
|
41
|
+
constructor(type, init) {
|
|
42
|
+
super(type);
|
|
43
|
+
this.request = init.request;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @param {Promise<Response> | Response} response */
|
|
47
|
+
respondWith(response) {
|
|
48
|
+
this._response = response;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ── Actual SW entry logic ──
|
|
54
|
+
|
|
55
|
+
const require = createRequire(import.meta.url);
|
|
56
|
+
|
|
57
|
+
const manifest = JSON.parse(
|
|
58
|
+
readFileSync(new URL("./manifest.json", import.meta.url), "utf-8"),
|
|
59
|
+
);
|
|
60
|
+
const bundle = require(`./server/${manifest.server.entry}`);
|
|
61
|
+
const app = bundle.createApp();
|
|
62
|
+
|
|
63
|
+
// SW fetch event
|
|
64
|
+
self.addEventListener("fetch", (event) => {
|
|
65
|
+
const url = new URL(event.request.url);
|
|
66
|
+
if (url.pathname.startsWith("/api/")) {
|
|
67
|
+
event.respondWith(app.fetch(event.request));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// ── Test helper: dispatch a mock FetchEvent and return the response ──
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Dispatch a mock fetch event through the SW handler.
|
|
75
|
+
* @param {Request} request
|
|
76
|
+
* @returns {Promise<Response | undefined>}
|
|
77
|
+
*/
|
|
78
|
+
export async function dispatchFetch(request) {
|
|
79
|
+
const event = new FetchEvent("fetch", { request });
|
|
80
|
+
const handlers = self.__listeners?.fetch || [];
|
|
81
|
+
for (const handler of handlers) {
|
|
82
|
+
handler(event);
|
|
83
|
+
}
|
|
84
|
+
return event._response ? await event._response : undefined;
|
|
85
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": ["src"],
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"jsx": "react-jsx",
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
|
8
|
+
"types": ["node"],
|
|
9
|
+
"moduleResolution": "Bundler",
|
|
10
|
+
"outDir": "./dist",
|
|
11
|
+
"rootDir": "./src",
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"verbatimModuleSyntax": true
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# basic-plugins
|
|
2
|
+
|
|
3
|
+
Demonstrates the evjs plugin system with all available hooks:
|
|
4
|
+
|
|
5
|
+
- **`bundler`** — modify the underlying bundler config (type-safe via `webpack()` helper)
|
|
6
|
+
- **`buildStart`** — run logic before compilation begins
|
|
7
|
+
- **`buildEnd`** — run logic after compilation completes
|
|
8
|
+
- **`transformHtml`** — modify the parsed HTML document after asset injection
|
|
9
|
+
|
|
10
|
+
## Run
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm run dev
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## What to look for
|
|
17
|
+
|
|
18
|
+
1. Console output from `buildStart` and `buildEnd` hooks during build
|
|
19
|
+
2. The `<!-- Built with evjs | N asset(s) -->` comment in the output HTML (injected by `transformHtml`)
|
|
20
|
+
3. `.txt` file support added via the `bundler` hook (webpack `raw-loader`)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { webpack } from "@evjs/bundler-webpack";
|
|
2
|
+
import { defineConfig } from "@evjs/ev";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Example: evjs plugin system.
|
|
6
|
+
*
|
|
7
|
+
* Demonstrates all available plugin hooks:
|
|
8
|
+
* - `bundler` — modify the underlying bundler config (type-safe via helpers)
|
|
9
|
+
* - `buildStart` — run logic before compilation begins
|
|
10
|
+
* - `buildEnd` — run logic after compilation completes
|
|
11
|
+
* - `transformHtml` — modify the output HTML document after asset injection
|
|
12
|
+
*/
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
server: false,
|
|
15
|
+
|
|
16
|
+
plugins: [
|
|
17
|
+
{
|
|
18
|
+
name: "example-txt-plugin",
|
|
19
|
+
setup(ctx) {
|
|
20
|
+
console.log(`[example-txt-plugin] mode: ${ctx.mode}`);
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
buildStart() {
|
|
24
|
+
console.log("[example-txt-plugin] build starting...");
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
// Type-safe webpack config mutation via the webpack() helper
|
|
28
|
+
bundler: webpack((config) => {
|
|
29
|
+
config.module?.rules?.push({
|
|
30
|
+
test: /\.txt$/,
|
|
31
|
+
use: "raw-loader",
|
|
32
|
+
});
|
|
33
|
+
}),
|
|
34
|
+
|
|
35
|
+
buildEnd(result) {
|
|
36
|
+
console.log(
|
|
37
|
+
`[example-txt-plugin] build complete — ${result.clientManifest.assets.js.length} JS asset(s)`,
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
// Modify the parsed HTML document after evjs injects script/link tags
|
|
42
|
+
transformHtml(doc, result) {
|
|
43
|
+
const assetCount =
|
|
44
|
+
result.clientManifest.assets.js.length +
|
|
45
|
+
result.clientManifest.assets.css.length;
|
|
46
|
+
|
|
47
|
+
const comment = doc.createComment(
|
|
48
|
+
` Built with evjs | ${assetCount} asset(s) `,
|
|
49
|
+
);
|
|
50
|
+
doc.head?.appendChild(comment);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "example-basic-plugins",
|
|
3
|
+
"version": "0.0.19",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "npx ev dev",
|
|
7
|
+
"build": "npx ev build",
|
|
8
|
+
"check-types": "tsc --noEmit"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"react": "^19.2.4",
|
|
12
|
+
"react-dom": "^19.2.4"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@evjs/bundler-webpack": "*",
|
|
16
|
+
"@evjs/cli": "*",
|
|
17
|
+
"@evjs/client": "*",
|
|
18
|
+
"@evjs/ev": "*",
|
|
19
|
+
"@evjs/server": "*",
|
|
20
|
+
"@types/react": "^19.1.8",
|
|
21
|
+
"@types/react-dom": "^19.1.8",
|
|
22
|
+
"raw-loader": "^4.0.2",
|
|
23
|
+
"typescript": "^6.0.2"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createApp } from "@evjs/client";
|
|
2
|
+
import { rootRoute } from "./pages/__root";
|
|
3
|
+
import { homeRoute } from "./pages/home";
|
|
4
|
+
|
|
5
|
+
const routeTree = rootRoute.addChildren([homeRoute]);
|
|
6
|
+
|
|
7
|
+
const app = createApp({ routeTree });
|
|
8
|
+
|
|
9
|
+
declare module "@tanstack/react-router" {
|
|
10
|
+
interface Register {
|
|
11
|
+
router: typeof app.router;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
app.render("#app");
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createRootRoute, Outlet } from "@evjs/client";
|
|
2
|
+
|
|
3
|
+
function Root() {
|
|
4
|
+
return (
|
|
5
|
+
<div style={{ fontFamily: "system-ui, sans-serif", padding: "1rem" }}>
|
|
6
|
+
<Outlet />
|
|
7
|
+
</div>
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const rootRoute = createRootRoute({
|
|
12
|
+
component: Root,
|
|
13
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createRoute } from "@evjs/client";
|
|
2
|
+
import { rootRoute } from "./__root";
|
|
3
|
+
|
|
4
|
+
function Home() {
|
|
5
|
+
return (
|
|
6
|
+
<div>
|
|
7
|
+
<h1>Plugin Example</h1>
|
|
8
|
+
<p>
|
|
9
|
+
This example demonstrates the evjs plugin system. Check{" "}
|
|
10
|
+
<code>ev.config.ts</code> to see how plugins work.
|
|
11
|
+
</p>
|
|
12
|
+
<p>
|
|
13
|
+
View the page source to see the HTML comment injected by{" "}
|
|
14
|
+
<code>transformHtml</code>.
|
|
15
|
+
</p>
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const homeRoute = createRoute({
|
|
21
|
+
getParentRoute: () => rootRoute,
|
|
22
|
+
path: "/",
|
|
23
|
+
component: Home,
|
|
24
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"jsx": "react-jsx",
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"moduleResolution": "Bundler",
|
|
9
|
+
"verbatimModuleSyntax": true,
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"noUnusedLocals": true,
|
|
14
|
+
"noUnusedParameters": true,
|
|
15
|
+
"noFallthroughCasesInSwitch": true
|
|
16
|
+
},
|
|
17
|
+
"include": ["src"]
|
|
18
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { createApp } from "@evjs/client";
|
|
2
|
-
import {
|
|
2
|
+
import { rootRoute } from "./pages/__root";
|
|
3
|
+
import { usersRoute } from "./pages/home";
|
|
4
|
+
|
|
5
|
+
const routeTree = rootRoute.addChildren([usersRoute]);
|
|
3
6
|
|
|
4
7
|
const app = createApp({ routeTree });
|
|
5
8
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createRootRoute, Link, Outlet } from "@evjs/client";
|
|
2
|
+
|
|
3
|
+
function Root() {
|
|
4
|
+
return (
|
|
5
|
+
<div style={{ fontFamily: "system-ui, sans-serif", padding: "1rem" }}>
|
|
6
|
+
<h1>Server Functions Example</h1>
|
|
7
|
+
<nav style={{ display: "flex", gap: "1rem", marginBottom: "1rem" }}>
|
|
8
|
+
<Link to="/">Users</Link>
|
|
9
|
+
</nav>
|
|
10
|
+
<Outlet />
|
|
11
|
+
</div>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const rootRoute = createRootRoute({ component: Root });
|
|
@@ -1,33 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createRootRoute,
|
|
3
2
|
createRoute,
|
|
4
3
|
getFnQueryKey,
|
|
5
|
-
Link,
|
|
6
|
-
Outlet,
|
|
7
4
|
useMutation,
|
|
8
5
|
useQuery,
|
|
9
6
|
useQueryClient,
|
|
10
7
|
} from "@evjs/client";
|
|
11
8
|
import { useState } from "react";
|
|
12
|
-
import { createUser, getUsers } from "
|
|
13
|
-
|
|
14
|
-
// ── Root Route ──
|
|
15
|
-
|
|
16
|
-
function Root() {
|
|
17
|
-
return (
|
|
18
|
-
<div style={{ fontFamily: "system-ui, sans-serif", padding: "1rem" }}>
|
|
19
|
-
<h1>Server Functions Example</h1>
|
|
20
|
-
<nav style={{ display: "flex", gap: "1rem", marginBottom: "1rem" }}>
|
|
21
|
-
<Link to="/">Users</Link>
|
|
22
|
-
</nav>
|
|
23
|
-
<Outlet />
|
|
24
|
-
</div>
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const rootRoute = createRootRoute({ component: Root });
|
|
29
|
-
|
|
30
|
-
// ── Users Route ──
|
|
9
|
+
import { createUser, getUsers } from "../api/users.server";
|
|
10
|
+
import { rootRoute } from "./__root";
|
|
31
11
|
|
|
32
12
|
function UsersPage() {
|
|
33
13
|
const [name, setName] = useState("");
|
|
@@ -85,12 +65,8 @@ function UsersPage() {
|
|
|
85
65
|
);
|
|
86
66
|
}
|
|
87
67
|
|
|
88
|
-
const usersRoute = createRoute({
|
|
68
|
+
export const usersRoute = createRoute({
|
|
89
69
|
getParentRoute: () => rootRoute,
|
|
90
70
|
path: "/",
|
|
91
71
|
component: UsersPage,
|
|
92
72
|
});
|
|
93
|
-
|
|
94
|
-
// ── Route Tree ──
|
|
95
|
-
|
|
96
|
-
export const routeTree = rootRoute.addChildren([usersRoute]);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { createApp } from "@evjs/client";
|
|
2
|
-
import {
|
|
2
|
+
import { rootRoute } from "./pages/__root";
|
|
3
|
+
import { postsRoute } from "./pages/home";
|
|
4
|
+
|
|
5
|
+
const routeTree = rootRoute.addChildren([postsRoute]);
|
|
3
6
|
|
|
4
7
|
const app = createApp({ routeTree });
|
|
5
8
|
|