wildpig 1.0.9 → 1.0.11

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.
Binary file
@@ -1,9 +1,11 @@
1
1
  import chalk from "chalk";
2
2
  import { htmlString } from "./htmlString";
3
3
  import { routes, metaRoutes } from "./prepareRoutes";
4
+ import { readFileSync } from "node:fs";
4
5
 
5
6
  const env = process.env;
6
7
 
8
+
7
9
  export const startServer = () => {
8
10
  Bun.serve({
9
11
  port: env.PORT || 3000,
@@ -16,8 +18,9 @@ export const startServer = () => {
16
18
  "content-type": "image/x-icon",
17
19
  }
18
20
  }),
19
- "/render.js": () => new Response(Bun.file("./public/render.js"), {
21
+ "/render.js": () => new Response((readFileSync("./public/render.js.br")), {
20
22
  headers: {
23
+ "Content-Encoding": "br",
21
24
  "content-type": "text/javascript; charset=utf-8",
22
25
  }
23
26
  }),
@@ -39,6 +42,7 @@ export const startServer = () => {
39
42
  })
40
43
  },
41
44
  },
45
+ development: false,
42
46
  })
43
47
  console.clear();
44
48
  console.log(` __ __ _ _ _ ____ _
@@ -94,6 +94,6 @@ export const genMetaRoutes = async () => {
94
94
  for(const route in routeScripts) {
95
95
  text += ` "${route}": require("${routeScripts[route]}").getMeta, \n`;
96
96
  }
97
- text += "},";
97
+ text += "}";
98
98
  writeFileSync("./build/built-meta-routes.ts", text);
99
99
  }
@@ -1,5 +1,6 @@
1
1
  import Bun from "bun";
2
- import fs from "node:fs";
2
+ import fs, { readFileSync, writeFileSync } from "node:fs";
3
+ import { brotliCompressSync } from "node:zlib";
3
4
 
4
5
 
5
6
  export const packageStatic = async () => {
@@ -10,6 +11,9 @@ export const packageStatic = async () => {
10
11
  format: "esm",
11
12
  minify: true,
12
13
  });
14
+ // 将 ./public/render.js 转为 ./public/render.br
15
+ writeFileSync("./dist/public/render.js.br", brotliCompressSync(Buffer.from(readFileSync("./dist/public/render.js"))));
16
+
13
17
  /** 打包ico */
14
18
  fs.copyFileSync("./public/favicon.ico", "./dist/public/favicon.ico");
15
19
  }
@@ -1,4 +1,6 @@
1
+ import { readFileSync, writeFileSync } from "node:fs";
1
2
  import { scanMetaRoutes, scanRoutes } from "./genRoutes";
3
+ import { brotliCompressSync } from "node:zlib";
2
4
 
3
5
  const isDev = process.env.NODE_ENV === "development";
4
6
 
@@ -14,9 +16,11 @@ if(isDev){
14
16
  await Bun.build({
15
17
  entrypoints: ["./public/render.tsx"],
16
18
  outdir: "./public",
17
- format: "esm",
19
+ format: "iife",
18
20
  minify: true,
19
21
  });
22
+ // 将 ./public/render.js 转为 ./public/render.br
23
+ writeFileSync("./public/render.js.br", brotliCompressSync(Buffer.from(readFileSync("./public/render.js"))));
20
24
  }else{
21
25
  routes = require("#/build/built-routes.ts").default;
22
26
  metaRoutes = require("#/build/built-meta-routes.ts").default;
package/src/App.tsx CHANGED
@@ -1,8 +1,7 @@
1
1
  import { RouterProvider } from "react-router";
2
2
  import { browserRouter } from "./router";
3
3
  import { RouterGuard } from "./router/guard";
4
- RouterGuard();
5
-
4
+ RouterGuard(browserRouter);
6
5
 
7
6
 
8
7
  export const App = () => <RouterProvider router={browserRouter} />;
@@ -4,7 +4,7 @@ import { Outlet } from "react-router";
4
4
 
5
5
  export const MainLayout = () => {
6
6
  return <div>
7
- MainLayout
7
+ Main5567
8
8
  <Outlet />
9
9
  </div>
10
10
  }
@@ -1,6 +1,6 @@
1
- import { browserRouter } from ".";
1
+ import type { BrowserRouter } from "."
2
2
 
3
- export const RouterGuard = () => {
3
+ export const RouterGuard = (browserRouter: BrowserRouter) => {
4
4
  // 每次跳转都会触发,包括 <Link>/navigate/前进后退
5
5
  browserRouter.subscribe(({ location }) => {
6
6
  // navigationType 值:'PUSH' | 'POP' | 'REPLACE'
@@ -1,5 +1,3 @@
1
- import { Index } from "@/page";
2
- import { Home } from "@/page/home/index";
3
1
  import { MainLayout } from "@/page/layout";
4
2
  import { createBrowserRouter } from "react-router";
5
3
 
@@ -7,15 +5,7 @@ export const browserRouter = createBrowserRouter([
7
5
  {
8
6
  path: "/",
9
7
  Component: MainLayout,
10
- children:[
11
- {
12
- path: "",
13
- Component: Index
14
- },
15
- {
16
- path: "home",
17
- Component: Home
18
- }
19
- ]
20
8
  },
21
- ]);
9
+ ]);
10
+
11
+ export type BrowserRouter = typeof browserRouter;