@shaper.org/vite-react-plugin 1.0.20 → 1.0.22
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.d.mts +18 -0
- package/dist/index.mjs +25 -17
- package/package.json +1 -1
- package/templates/main-generouted.ts +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -12,6 +12,24 @@ declare const reactPlugin: (config: ReactPluginConfig) => ({
|
|
|
12
12
|
code: any;
|
|
13
13
|
map: null;
|
|
14
14
|
} | null>;
|
|
15
|
+
} | {
|
|
16
|
+
name: string;
|
|
17
|
+
enforce: string;
|
|
18
|
+
apply: string;
|
|
19
|
+
configResolved(resolvedConfig: vite0.ResolvedConfig): void;
|
|
20
|
+
resolveId(id: string): "virtual:routes-listening" | undefined;
|
|
21
|
+
load(id: string): string | undefined;
|
|
22
|
+
transformIndexHtml(html: string): Promise<{
|
|
23
|
+
html: string;
|
|
24
|
+
tags: {
|
|
25
|
+
tag: string;
|
|
26
|
+
injectTo: string;
|
|
27
|
+
attrs: {
|
|
28
|
+
src: string;
|
|
29
|
+
type: string;
|
|
30
|
+
};
|
|
31
|
+
}[];
|
|
32
|
+
}>;
|
|
15
33
|
} | {
|
|
16
34
|
name: string;
|
|
17
35
|
enforce: string;
|
package/dist/index.mjs
CHANGED
|
@@ -37,8 +37,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
37
37
|
|
|
38
38
|
//#endregion
|
|
39
39
|
//#region src/react-route-plugin.ts
|
|
40
|
-
const mainContentPath
|
|
41
|
-
const appendTo
|
|
40
|
+
const mainContentPath = join(dirname(fileURLToPath(import.meta.url)), "../templates/main.ts");
|
|
41
|
+
const appendTo = "src/main.tsx";
|
|
42
42
|
const reactRoutesPlugin = () => {
|
|
43
43
|
return {
|
|
44
44
|
name: "react-routes-plugin",
|
|
@@ -48,8 +48,8 @@ const reactRoutesPlugin = () => {
|
|
|
48
48
|
async transform(code, id, options) {
|
|
49
49
|
if (options?.ssr) return;
|
|
50
50
|
const [filename] = id.split("?", 2);
|
|
51
|
-
if (typeof appendTo
|
|
52
|
-
const transformed = await transform(await readFile(mainContentPath
|
|
51
|
+
if (typeof appendTo === "string" && filename.endsWith(appendTo)) {
|
|
52
|
+
const transformed = await transform(await readFile(mainContentPath, { encoding: "utf-8" }), {
|
|
53
53
|
loader: "ts",
|
|
54
54
|
format: "esm",
|
|
55
55
|
target: "es2022"
|
|
@@ -63,26 +63,34 @@ const reactRoutesPlugin = () => {
|
|
|
63
63
|
|
|
64
64
|
//#endregion
|
|
65
65
|
//#region src/react-route-generouted.ts
|
|
66
|
-
|
|
67
|
-
const appendTo = "src/main.tsx";
|
|
66
|
+
join(dirname(fileURLToPath(import.meta.url)), "../templates/main-generouted.ts");
|
|
68
67
|
const reactRoutesGeneroutedPlugin = () => {
|
|
69
68
|
return {
|
|
70
69
|
name: "react-routes-plugin",
|
|
71
70
|
enforce: "post",
|
|
72
71
|
apply: "serve",
|
|
73
72
|
configResolved(resolvedConfig) {},
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
target: "es2022"
|
|
82
|
-
});
|
|
83
|
-
code = `${code}\n${transformed.code}`;
|
|
73
|
+
resolveId(id) {
|
|
74
|
+
if (id === "virtual:routes-listening") return id;
|
|
75
|
+
},
|
|
76
|
+
load(id) {
|
|
77
|
+
if (id === "virtual:routes-listening") {
|
|
78
|
+
const runtimePath = fileURLToPath(new URL("../templates/main-generouted", import.meta.url));
|
|
79
|
+
return `import ${JSON.stringify(runtimePath)};`;
|
|
84
80
|
}
|
|
85
|
-
|
|
81
|
+
},
|
|
82
|
+
async transformIndexHtml(html) {
|
|
83
|
+
return {
|
|
84
|
+
html,
|
|
85
|
+
tags: [{
|
|
86
|
+
tag: "script",
|
|
87
|
+
injectTo: "body",
|
|
88
|
+
attrs: {
|
|
89
|
+
src: "/@id/virtual:routes-listening",
|
|
90
|
+
type: "module"
|
|
91
|
+
}
|
|
92
|
+
}]
|
|
93
|
+
};
|
|
86
94
|
}
|
|
87
95
|
};
|
|
88
96
|
};
|
package/package.json
CHANGED
|
@@ -153,7 +153,7 @@ export class ReactRouteMonitor {
|
|
|
153
153
|
const routes = validRoutes.map((route) => ({
|
|
154
154
|
name: route.id,
|
|
155
155
|
path: route.id === "index" ? route.path : `/${route.path}`,
|
|
156
|
-
file: `src/${route.id}.tsx`,
|
|
156
|
+
file: `src/pages/${route.id}.tsx`,
|
|
157
157
|
}));
|
|
158
158
|
|
|
159
159
|
this.iframeClient.sendAllRoutes(routes);
|
|
@@ -191,7 +191,7 @@ export class ReactRouteMonitor {
|
|
|
191
191
|
const routeInfo = {
|
|
192
192
|
name: to.id,
|
|
193
193
|
path: to.id === "index" ? to.path : `/${to.path}`,
|
|
194
|
-
file: `src/${to.id}.tsx`,
|
|
194
|
+
file: `src/pages/${to.id}.tsx`,
|
|
195
195
|
};
|
|
196
196
|
this.iframeClient.sendRouteChange(routeInfo);
|
|
197
197
|
};
|