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.
- package/README.md +5 -1
- package/build/built-routes.ts +1 -1
- package/package.json +1 -1
- package/public/render.js +84 -84
- package/public/render.js.br +0 -0
- package/scripts/WildPig.ts +5 -1
- package/scripts/genRoutes.ts +1 -1
- package/scripts/packageStatic.ts +5 -1
- package/scripts/prepareRoutes.ts +5 -1
- package/src/App.tsx +1 -2
- package/src/page/layout.tsx +1 -1
- package/src/router/guard.tsx +2 -2
- package/src/router/index.tsx +3 -13
|
Binary file
|
package/scripts/WildPig.ts
CHANGED
|
@@ -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(
|
|
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(` __ __ _ _ _ ____ _
|
package/scripts/genRoutes.ts
CHANGED
package/scripts/packageStatic.ts
CHANGED
|
@@ -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
|
}
|
package/scripts/prepareRoutes.ts
CHANGED
|
@@ -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: "
|
|
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
package/src/page/layout.tsx
CHANGED
package/src/router/guard.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
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'
|
package/src/router/index.tsx
CHANGED
|
@@ -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;
|