vike-lite 1.6.1 → 1.6.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/dist/vite.mjs +10 -23
- package/package.json +1 -1
package/dist/vite.mjs
CHANGED
|
@@ -4,11 +4,6 @@ import { Readable } from "node:stream";
|
|
|
4
4
|
import { pipeline } from "node:stream/promises";
|
|
5
5
|
import { loadEnv } from "vite";
|
|
6
6
|
//#region src/utils/generateRoutes.ts
|
|
7
|
-
const pageExtensions = [".ts", ".js"];
|
|
8
|
-
const pageExtensionsX = [".tsx", ".jsx"];
|
|
9
|
-
function findFile(files, basename, extensions) {
|
|
10
|
-
return files.find((file) => extensions.some((ext) => file === `${basename}${ext}`));
|
|
11
|
-
}
|
|
12
7
|
function generateRoutes(viteRoot, pagesDir) {
|
|
13
8
|
const pagesAbsPath = path.resolve(viteRoot, pagesDir);
|
|
14
9
|
if (!fs.existsSync(pagesAbsPath)) return { routes: [] };
|
|
@@ -17,22 +12,15 @@ function generateRoutes(viteRoot, pagesDir) {
|
|
|
17
12
|
function walk(dir, routePath, parentLayout, parentHead) {
|
|
18
13
|
const files = fs.readdirSync(dir);
|
|
19
14
|
const importPath = path.relative(viteRoot, dir).replaceAll("\\", "/");
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const currentHead = headFile ? `${importPath}/${headFile}` : parentHead;
|
|
24
|
-
const pageFile = findFile(files, "+Page", pageExtensionsX);
|
|
25
|
-
if (pageFile) {
|
|
26
|
-
const dataFile = findFile(files, "+data", pageExtensions);
|
|
27
|
-
const titleFile = findFile(files, "+title", pageExtensions);
|
|
15
|
+
const currentLayout = files.includes("+Layout.tsx") ? `${importPath}/+Layout.tsx` : parentLayout;
|
|
16
|
+
const currentHead = files.includes("+Head.tsx") ? `${importPath}/+Head.tsx` : parentHead;
|
|
17
|
+
if (files.includes("+Page.tsx")) {
|
|
28
18
|
const route = {
|
|
29
19
|
path: routePath || "/",
|
|
30
|
-
page: `${importPath}
|
|
31
|
-
hasData:
|
|
32
|
-
hasTitle:
|
|
20
|
+
page: `${importPath}/+Page.tsx`,
|
|
21
|
+
hasData: files.includes("+data.ts"),
|
|
22
|
+
hasTitle: files.includes("+title.ts")
|
|
33
23
|
};
|
|
34
|
-
if (dataFile) route.data = `${importPath}/${dataFile}`;
|
|
35
|
-
if (titleFile) route.title = `${importPath}/${titleFile}`;
|
|
36
24
|
if (currentLayout) route.layout = currentLayout;
|
|
37
25
|
if (currentHead) route.head = currentHead;
|
|
38
26
|
routes.push(route);
|
|
@@ -41,10 +29,9 @@ function generateRoutes(viteRoot, pagesDir) {
|
|
|
41
29
|
const fullPath = path.join(dir, file);
|
|
42
30
|
if (!fs.statSync(fullPath).isDirectory()) continue;
|
|
43
31
|
if (file === "_error") {
|
|
44
|
-
|
|
45
|
-
if (errorPageFile) errorRoute = {
|
|
32
|
+
if (fs.readdirSync(fullPath).includes("+Page.tsx")) errorRoute = {
|
|
46
33
|
path: "_error",
|
|
47
|
-
page: `${importPath}/_error
|
|
34
|
+
page: `${importPath}/_error/+Page.tsx`,
|
|
48
35
|
layout: currentLayout,
|
|
49
36
|
head: currentHead
|
|
50
37
|
};
|
|
@@ -187,8 +174,8 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
|
|
|
187
174
|
if (r.layout) code += `layout:'${r.layout}',Layout:()=>import('/${r.layout}'),`;
|
|
188
175
|
code += `hasData:${r.hasData},hasTitle:${r.hasTitle},`;
|
|
189
176
|
if (isSSR) {
|
|
190
|
-
if (r.hasData) code += `data:()=>import('/${r.data}'),`;
|
|
191
|
-
if (r.hasTitle) code += `title:()=>import('/${r.title}'),`;
|
|
177
|
+
if (r.hasData) code += `data:()=>import('/${r.page.replace("+Page.tsx", "+data.ts")}'),`;
|
|
178
|
+
if (r.hasTitle) code += `title:()=>import('/${r.page.replace("+Page.tsx", "+title.ts")}'),`;
|
|
192
179
|
}
|
|
193
180
|
code += "},";
|
|
194
181
|
}
|