wildpig 1.1.0 → 1.1.2

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/README.md CHANGED
@@ -10,8 +10,8 @@
10
10
 
11
11
  * 前后端同构,一套代码,函数复用。
12
12
 
13
- * SEO友好,支持服务端渲染meta信息。
13
+ * 【超级重要】SEO友好,支持服务端渲染meta信息。
14
14
 
15
- * 服务端路由自动生成。
15
+ * 服务端路由根据文件路径自动生成。
16
16
 
17
- * 前端开发热重载(和vite一样)。
17
+ * 前端开发热重载。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wildpig",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "author": "eriktse",
5
5
  "main": "index.ts",
6
6
  "dependencies": {
@@ -11,7 +11,7 @@
11
11
  "react": "^19.2.3",
12
12
  "react-dom": "^19.2.3"
13
13
  },
14
- "description": "A strong and fast fullstack framework base Bun.",
14
+ "description": "A strong and fast fullstack framework base on Bun, react, react-router, typescript, tailwindcss.",
15
15
  "keywords": [
16
16
  "fullstack",
17
17
  "web",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "license": "ISC",
21
21
  "scripts": {
22
- "dev": "export NODE_ENV=development && bun run test.ts",
22
+ "dev": "export NODE_ENV=development && bun run --hot test.ts",
23
23
  "prebuild": "bun run scripts/run-prebuild.ts",
24
24
  "build": "export NODE_ENV=production && bun run prebuild && bun build --compile ./test.ts --outfile dist/wildpig",
25
25
  "build-linux-musl": "export NODE_ENV=production && bun build --compile --target=bun-linux-x64-musl ./test.ts --outfile dist/wildpig",
package/public/index.html CHANGED
@@ -3,8 +3,13 @@
3
3
  <head>
4
4
  <meta charset="UTF-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <script src="/render.js" type="module"></script>
6
+ <meta name="wildpig-environment" content="production">
7
+
7
8
  <title>{{TITLE}}</title>
9
+ <meta name="description" content="{{DESCRIPTION}}">
10
+ <meta name="keywords" content="{{KEYWORDS}}">
11
+
12
+ <script src="/render.js" type="module"></script>
8
13
  </head>
9
14
  <body>
10
15
  <div id="root"></div>
package/public/render.js CHANGED
@@ -22344,26 +22344,12 @@ function useViewTransitionState(to, { relative } = {}) {
22344
22344
 
22345
22345
  // node_modules/react-router/dist/development/index.mjs
22346
22346
  "use client";
22347
-
22348
22347
  // src/page/layout.tsx
22349
22348
  var jsx_dev_runtime = __toESM(require_jsx_dev_runtime(), 1);
22350
22349
  var MainLayout = () => {
22351
22350
  return /* @__PURE__ */ jsx_dev_runtime.jsxDEV("div", {
22352
- children: [
22353
- /* @__PURE__ */ jsx_dev_runtime.jsxDEV("input", {
22354
- type: "text",
22355
- placeholder: "Search"
22356
- }, undefined, false, undefined, this),
22357
- /* @__PURE__ */ jsx_dev_runtime.jsxDEV("button", {
22358
- children: "Search"
22359
- }, undefined, false, undefined, this),
22360
- /* @__PURE__ */ jsx_dev_runtime.jsxDEV("div", {
22361
- className: "text-red-500",
22362
- children: "红红红"
22363
- }, undefined, false, undefined, this),
22364
- /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Outlet, {}, undefined, false, undefined, this)
22365
- ]
22366
- }, undefined, true, undefined, this);
22351
+ children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Outlet, {}, undefined, false, undefined, this)
22352
+ }, undefined, false, undefined, this);
22367
22353
  };
22368
22354
 
22369
22355
  // src/router/index.tsx
Binary file
@@ -0,0 +1 @@
1
+ export * from "react-router";
@@ -7,6 +7,8 @@ import devIndexHtml from "#/public/devIndex.html"
7
7
  const env = process.env;
8
8
  const isDev = env.NODE_ENV === "development";
9
9
 
10
+ console.log(metaRoutes);
11
+
10
12
 
11
13
  export const startServer = () => {
12
14
  Bun.serve({
@@ -27,17 +29,25 @@ export const startServer = () => {
27
29
  "Cache-Control": isDev ? "no-cache" : "public, max-age=31536000, immutable"
28
30
  }
29
31
  }),
30
- "/*": isDev ? devIndexHtml : async (request) => {
31
- const url = "/" + (request.url.split("/")[3] || "");
32
- // console.log("url:", url);
33
- const pathname = "/_WILDPIG_META_API" + url.split("?")[0];
34
- let meta: {title: string} | null = null;
32
+ "/*":
33
+ isDev ? devIndexHtml :
34
+ async (request: Request) => {
35
+ const pathname = "/_WILDPIG_META_API/" + (request.url.split("/")[3].split("?")[0] || "");
36
+ let resHtml = htmlString;
35
37
 
36
38
  if(pathname in metaRoutes){
37
- const metaRes = await metaRoutes[pathname]();
38
- meta = await metaRes.json();
39
+ try{
40
+ const metaResponse = await metaRoutes[pathname](request);
41
+ const meta = await metaResponse.json();
42
+ if(meta.title)resHtml = resHtml.replace("{{TITLE}}", meta.title);
43
+ if(meta.description)resHtml = resHtml.replace("{{DESCRIPTION}}", meta.description);
44
+ if(meta.keywords)resHtml = resHtml.replace("{{KEYWORDS}}", meta.keywords.join(", "));
45
+ }catch(e){
46
+ console.error("获取meta信息失败,请检查是否设置了meta信息", e);
47
+ }
39
48
  }
40
- return new Response(htmlString.replace("{{TITLE}}", meta?.title || "WildPig"), {
49
+
50
+ return new Response(resHtml, {
41
51
  headers: {
42
52
  "content-type": "text/html; charset=utf-8",
43
53
  "Access-Control-Allow-Origin": "*",
@@ -6,7 +6,7 @@ const isDev = process.env.NODE_ENV === "development";
6
6
 
7
7
  // 准备服务端路由表
8
8
  let routes = {};
9
- let metaRoutes: Record<string, () => Promise<Response>> = {};
9
+ let metaRoutes: Record<string, (req: Request) => Promise<Response>> = {};
10
10
  if(isDev){
11
11
  // 引入,用于监听
12
12
  setTimeout(() => import("@/App").catch(() => {}), 1000);