@evjs/create-app 0.0.15 → 0.0.17
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/dist/index.js +1 -1
- package/package.json +1 -1
- package/templates/basic-csr/ev.config.ts +5 -0
- package/templates/basic-csr/package.json +1 -1
- package/templates/basic-server-fns/package.json +1 -1
- package/templates/basic-server-fns/src/routes.tsx +26 -33
- package/templates/basic-server-routes/package.json +1 -1
- package/templates/complex-routing/package.json +1 -1
- package/templates/configured-server-fns/README.md +1 -0
- package/templates/configured-server-fns/ev.config.ts +12 -10
- package/templates/configured-server-fns/package.json +1 -1
- package/templates/with-tailwind/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -92,7 +92,7 @@ program
|
|
|
92
92
|
};
|
|
93
93
|
updateDeps(projPkg.dependencies);
|
|
94
94
|
updateDeps(projPkg.devDependencies);
|
|
95
|
-
|
|
95
|
+
fs.writeFileSync(pkgPath, JSON.stringify(projPkg, null, 2));
|
|
96
96
|
}
|
|
97
97
|
console.log(pc.green("✔ Done! Now run:"));
|
|
98
98
|
console.log(` cd ${projectName}`);
|
package/package.json
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
createRootRoute,
|
|
3
|
+
createRoute,
|
|
4
|
+
getFnQueryKey,
|
|
5
|
+
Link,
|
|
6
|
+
Outlet,
|
|
7
|
+
useMutation,
|
|
8
|
+
useQuery,
|
|
9
|
+
useQueryClient,
|
|
10
|
+
} from "@evjs/client";
|
|
11
|
+
import { useState } from "react";
|
|
3
12
|
import { createUser, getUsers } from "./api/users.server";
|
|
4
13
|
|
|
5
14
|
// ── Root Route ──
|
|
@@ -23,42 +32,26 @@ const rootRoute = createRootRoute({ component: Root });
|
|
|
23
32
|
function UsersPage() {
|
|
24
33
|
const [name, setName] = useState("");
|
|
25
34
|
const [email, setEmail] = useState("");
|
|
35
|
+
const queryClient = useQueryClient();
|
|
26
36
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
>([]);
|
|
30
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
37
|
+
// Use the framework's useQuery hook instead of manual useState + useEffect
|
|
38
|
+
const { data: users = [], isLoading } = useQuery(getUsers);
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
console.error(err);
|
|
43
|
-
if (mounted) setIsLoading(false);
|
|
44
|
-
});
|
|
45
|
-
return () => {
|
|
46
|
-
mounted = false;
|
|
47
|
-
};
|
|
48
|
-
}, []);
|
|
40
|
+
// Use useMutation for server function calls that modify data
|
|
41
|
+
const createUserMutation = useMutation({
|
|
42
|
+
mutationFn: createUser,
|
|
43
|
+
onSuccess: () => {
|
|
44
|
+
// Invalidate and refetch users list after successful creation
|
|
45
|
+
queryClient.invalidateQueries({ queryKey: getFnQueryKey(getUsers) });
|
|
46
|
+
setName("");
|
|
47
|
+
setEmail("");
|
|
48
|
+
},
|
|
49
|
+
});
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
function handleCreate(e: { preventDefault: () => void }) {
|
|
51
52
|
e.preventDefault();
|
|
52
53
|
if (!name || !email) return;
|
|
53
|
-
|
|
54
|
-
await createUser({ name, email });
|
|
55
|
-
setName("");
|
|
56
|
-
setEmail("");
|
|
57
|
-
const data = await getUsers();
|
|
58
|
-
setUsers(data);
|
|
59
|
-
} catch (err) {
|
|
60
|
-
console.error(err);
|
|
61
|
-
}
|
|
54
|
+
createUserMutation.mutate({ name, email });
|
|
62
55
|
}
|
|
63
56
|
|
|
64
57
|
if (isLoading) return <p>Loading users from server…</p>;
|
|
@@ -19,6 +19,7 @@ npm run dev -w example-configured-server-fns
|
|
|
19
19
|
## What It Demonstrates
|
|
20
20
|
|
|
21
21
|
- `ev.config.ts` with `defineConfig` for custom ports
|
|
22
|
+
- Plugin with `setup()` → `bundler: webpack(...)` for type-safe webpack config
|
|
22
23
|
- `useQuery(getUsers)` for fetching data with auto-generated keys
|
|
23
24
|
- `useMutation({ mutationFn })` with `getUsers.queryKey()` for cache invalidation
|
|
24
25
|
- Direct mutation args: `mutate({ name, email })` (not array-wrapped)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { webpack } from "@evjs/bundler-webpack";
|
|
1
2
|
import { defineConfig } from "@evjs/cli";
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -37,19 +38,20 @@ export default defineConfig({
|
|
|
37
38
|
},
|
|
38
39
|
},
|
|
39
40
|
|
|
40
|
-
// Build-time plugins
|
|
41
|
+
// Build-time plugins
|
|
41
42
|
plugins: [
|
|
42
43
|
{
|
|
43
44
|
name: "example-txt-plugin",
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
setup() {
|
|
46
|
+
return {
|
|
47
|
+
// Type-safe webpack config via helper
|
|
48
|
+
bundler: webpack((config) => {
|
|
49
|
+
config.module?.rules?.push({
|
|
50
|
+
test: /\.txt$/,
|
|
51
|
+
use: "raw-loader",
|
|
52
|
+
});
|
|
53
|
+
}),
|
|
54
|
+
};
|
|
53
55
|
},
|
|
54
56
|
},
|
|
55
57
|
],
|