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.
Files changed (2) hide show
  1. package/dist/vite.mjs +10 -23
  2. 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 layoutFile = findFile(files, "+Layout", pageExtensionsX);
21
- const currentLayout = layoutFile ? `${importPath}/${layoutFile}` : parentLayout;
22
- const headFile = findFile(files, "+Head", pageExtensionsX);
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}/${pageFile}`,
31
- hasData: dataFile !== void 0,
32
- hasTitle: titleFile !== void 0
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
- const errorPageFile = findFile(fs.readdirSync(fullPath), "+Page", pageExtensionsX);
45
- if (errorPageFile) errorRoute = {
32
+ if (fs.readdirSync(fullPath).includes("+Page.tsx")) errorRoute = {
46
33
  path: "_error",
47
- page: `${importPath}/_error/${errorPageFile}`,
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-lite",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",