vite-react-ssg 0.0.1

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.
@@ -0,0 +1,141 @@
1
+ import { Options } from 'critters';
2
+ import { ReactNode } from 'react';
3
+ import { RouteObject, createBrowserRouter } from 'react-router-dom';
4
+
5
+ type Router = ReturnType<typeof createBrowserRouter>;
6
+ interface ViteReactSSGOptions {
7
+ /**
8
+ * Set the scripts' loading mode. Only works for `type="module"`.
9
+ *
10
+ * @default 'sync'
11
+ */
12
+ script?: 'sync' | 'async' | 'defer' | 'async defer';
13
+ /**
14
+ * Build format.
15
+ *
16
+ * @default 'esm'
17
+ */
18
+ format?: 'esm' | 'cjs';
19
+ /**
20
+ * The path of the main entry file (relative to the project root).
21
+ *
22
+ * @default 'src/main.ts'
23
+ */
24
+ entry?: string;
25
+ /**
26
+ * Mock browser global variables (window, document, etc...) from SSG.
27
+ *
28
+ * @default false
29
+ */
30
+ mock?: boolean;
31
+ /**
32
+ * Apply formatter to the generated index file.
33
+ *
34
+ * @default 'none'
35
+ */
36
+ formatting?: 'minify' | 'prettify' | 'none';
37
+ /**
38
+ * Vite environmeng mode.
39
+ */
40
+ mode?: string;
41
+ /**
42
+ * Directory style of the output directory.
43
+ *
44
+ * flat: `/foo` -> `/foo.html`
45
+ * nested: `/foo` -> `/foo/index.html`
46
+ *
47
+ * @default 'flat'
48
+ */
49
+ dirStyle?: 'flat' | 'nested';
50
+ /**
51
+ * Generate for all routes, including dynamic routes.
52
+ * If enabled, you will need to configGure your serve
53
+ * manually to handle dynamic routes properly.
54
+ *
55
+ * @default false
56
+ */
57
+ includeAllRoutes?: boolean;
58
+ /**
59
+ * Options for the critters packages.
60
+ *
61
+ * @see https://github.com/GoogleChromeLabs/critters
62
+ */
63
+ crittersOptions?: Options | false;
64
+ /**
65
+ * Custom function to modify the routes to do the SSG.
66
+ *
67
+ * Works only when `includeAllRoutes` is set to false.
68
+ *
69
+ * Defaults to a handler that filters out all the dynamic routes.
70
+ * When passing your custom handler, you should also take care of the dynamic routes yourself.
71
+ */
72
+ includedRoutes?: (paths: string[], routes: Readonly<RouteRecord[]>) => Promise<string[]> | string[];
73
+ /**
74
+ * Callback to be called before every page render.
75
+ *
76
+ * It can be used to transform the project's `index.html` file before passing it to the renderer.
77
+ *
78
+ * To do so, you can change the 'index.html' file contents (passed in through the `indexHTML` parameter), and return it.
79
+ * The returned value will then be passed to renderer.
80
+ */
81
+ onBeforePageRender?: (route: string, indexHTML: string, appCtx: ViteReactSSGContext<true>) => Promise<string | null | undefined> | string | null | undefined;
82
+ /**
83
+ * Callback to be called on every rendered page.
84
+ *
85
+ * It can be used to transform the current route's rendered HTML.
86
+ *
87
+ * To do so, you can transform the route's rendered HTML (passed in through the `renderedHTML` parameter), and return it.
88
+ * The returned value will be used as the HTML of the route.
89
+ */
90
+ onPageRendered?: (route: string, renderedHTML: string, appCtx: ViteReactSSGContext<true>) => Promise<string | null | undefined> | string | null | undefined;
91
+ onFinished?: () => Promise<void> | void;
92
+ /**
93
+ * The application's root container `class`.
94
+ *
95
+ * @default `root`
96
+ */
97
+ rootContainerId?: string;
98
+ /**
99
+ * The size of the SSG processing queue.
100
+ *
101
+ * @default 20
102
+ */
103
+ concurrency?: number;
104
+ }
105
+ interface ViteReactSSGContext<HasRouter extends boolean = true> {
106
+ app?: ReactNode;
107
+ router?: HasRouter extends true ? Router : undefined;
108
+ routes: HasRouter extends true ? Readonly<RouteRecord[]> : undefined;
109
+ routerOptions: RouterOptions;
110
+ initialState: Record<string, any>;
111
+ isClient: boolean;
112
+ onSSRAppRendered(cb: Function): void;
113
+ triggerOnSSRAppRendered(route: string, appHTML: string, appCtx: ViteReactSSGContext): Promise<unknown[]>;
114
+ transformState?(state: any): any;
115
+ /**
116
+ * Current router path on SSG, `undefined` on client side.
117
+ */
118
+ routePath?: string;
119
+ }
120
+ interface ViteReactSSGClientOptions {
121
+ transformState?: (state: any) => any;
122
+ registerComponents?: boolean;
123
+ /**
124
+ * The application's root container query selector.
125
+ *
126
+ * @default `#root`
127
+ */
128
+ rootContainer?: string | Element;
129
+ }
130
+ type RouteRecord = RouteObject & {};
131
+ interface RouterOptions {
132
+ routes: RouteRecord[];
133
+ createFetchRequest?: <T>(req: T) => Request;
134
+ }
135
+ declare module 'vite' {
136
+ interface UserConfig {
137
+ ssgOptions?: ViteReactSSGOptions;
138
+ }
139
+ }
140
+
141
+ export { RouterOptions as R, ViteReactSSGContext as V, ViteReactSSGClientOptions as a, ViteReactSSGOptions as b };
package/package.json ADDED
@@ -0,0 +1,112 @@
1
+ {
2
+ "name": "vite-react-ssg",
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "packageManager": "pnpm@8.6.6",
6
+ "description": "",
7
+ "author": "Riri <Daydreamerriri@outlook.com>",
8
+ "license": "MIT",
9
+ "homepage": "https://github.com/Daydreamer-riri/vite-react-ssg#readme",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/Daydreamer-riri/vite-react-ssg.git"
13
+ },
14
+ "bugs": "https://github.com/Daydreamer-riri/vite-react-ssg/issues",
15
+ "keywords": [
16
+ "vite",
17
+ "vite-plugin",
18
+ "ssg",
19
+ "ssr",
20
+ "react"
21
+ ],
22
+ "sideEffects": false,
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "require": "./dist/index.cjs",
27
+ "import": "./dist/index.mjs"
28
+ },
29
+ "./node": {
30
+ "types": "./dist/node.d.ts",
31
+ "require": "./dist/node.cjs",
32
+ "import": "./dist/node.mjs"
33
+ }
34
+ },
35
+ "main": "./dist/index.mjs",
36
+ "module": "./dist/index.mjs",
37
+ "types": "./dist/index.d.ts",
38
+ "typesVersions": {
39
+ "*": {
40
+ "node": [
41
+ "./dist/node.d.ts"
42
+ ]
43
+ }
44
+ },
45
+ "bin": {
46
+ "vite-react-ssg": "bin/vite-react-ssg.js"
47
+ },
48
+ "files": [
49
+ "dist",
50
+ "bin",
51
+ "*.d.ts"
52
+ ],
53
+ "scripts": {
54
+ "build": "unbuild",
55
+ "dev": "unbuild --stub",
56
+ "lint": "eslint .",
57
+ "prepublishOnly": "nr build",
58
+ "release": "bumpp && npm publish",
59
+ "start": "esno src/index.ts",
60
+ "typecheck": "tsc --noEmit"
61
+ },
62
+ "peerDependencies": {
63
+ "critters": "^0.0.19",
64
+ "react": "^18.0.0",
65
+ "react-dom": "^18.0.0",
66
+ "react-router-dom": "^6.14.1",
67
+ "vite": "^2.0.0 || ^3.0.0 || ^4.0.0"
68
+ },
69
+ "peerDependenciesMeta": {
70
+ "critters": {
71
+ "optional": true
72
+ },
73
+ "react-router-dom": {
74
+ "optional": true
75
+ }
76
+ },
77
+ "dependencies": {
78
+ "fs-extra": "^11.1.1",
79
+ "html-minifier": "^4.0.0",
80
+ "html5parser": "^2.0.2",
81
+ "jsdom": "^22.1.0",
82
+ "kolorist": "^1.8.0",
83
+ "react-helmet-async": "^1.3.0",
84
+ "yargs": "^17.7.2"
85
+ },
86
+ "devDependencies": {
87
+ "@ririd/eslint-config": "0.5.1",
88
+ "@types/fs-extra": "^11.0.1",
89
+ "@types/html-minifier": "^4.0.2",
90
+ "@types/jsdom": "^21.1.1",
91
+ "@types/node": "^18.15.11",
92
+ "@types/react": "^18.2.14",
93
+ "@types/react-dom": "^18.2.6",
94
+ "@types/react-helmet-async": "^1.0.3",
95
+ "@types/yargs": "^17.0.24",
96
+ "bumpp": "^9.1.0",
97
+ "critters": "^0.0.19",
98
+ "eslint": "^8.40.0",
99
+ "esno": "^0.16.3",
100
+ "p-queue": "^7.3.4",
101
+ "react": "^18.2.0",
102
+ "react-dom": "^18.2.0",
103
+ "react-router-dom": "^6.14.1",
104
+ "rimraf": "5.0.1",
105
+ "simple-git-hooks": "^2.8.1",
106
+ "typescript": "5.1.6",
107
+ "unbuild": "^1.2.1",
108
+ "vite": "^4.3.9",
109
+ "vite-plugin-pwa": "^0.16.4",
110
+ "vitest": "0.33.0"
111
+ }
112
+ }