diff --git a/packages/core/src/context.ts b/packages/core/src/context.ts index 8a752d6..b22c569 100644 --- a/packages/core/src/context.ts +++ b/packages/core/src/context.ts @@ -165,15 +165,15 @@ export class PageContext { ? mergePageMetaDataArray(generatedPageMetaData.concat(customPageMetaData)) : generatedPageMetaData - this.hasHome(result) + this.setHomePage(result) result.sort(page => (page.type === 'home' ? -1 : 0)) return result } - hasHome(result: PageMetaDatum[]) { - const isHome = result.some((page) => { + setHomePage(result: PageMetaDatum[]) { + const hasHome = result.some((page) => { if (page.type === 'home') return true @@ -185,22 +185,23 @@ export class PageContext { return false }) - if (isHome) + if (hasHome) return true - const findHome = result.some((item) => { - if (this.options.homePage === item.path) { + const isFoundHome = result.some((item) => { + if (this.options.homePage.includes(item.path)) { item.type = 'home' return true } - else { - return false - } + else { return false } }) - if (findHome) - return true - else console.warn('No home page found, please check the configuration of pages.config.ts') + if (isFoundHome) { return true } + else { + this.logger?.warn('No home page found, check the configuration of pages.config.ts, or add the `homePage` option to UniPages in vite.config.js, or add `type="home"` to the routeBlock of your vue page.', { + timestamp: true, + }) + } } async mergePageMetaData() { diff --git a/packages/core/src/files.ts b/packages/core/src/files.ts index 68df835..4c19a60 100644 --- a/packages/core/src/files.ts +++ b/packages/core/src/files.ts @@ -1,4 +1,4 @@ -import fs from 'fs' +import fs from 'node:fs' import fg from 'fast-glob' import { extsToGlob } from './utils' diff --git a/packages/core/src/options.ts b/packages/core/src/options.ts index a38a800..3de0174 100644 --- a/packages/core/src/options.ts +++ b/packages/core/src/options.ts @@ -4,7 +4,7 @@ import type { ResolvedOptions, UserOptions } from './types' export function resolveOptions(userOptions: UserOptions, viteRoot?: string): ResolvedOptions { const { - homePage = 'pages/index', + homePage = ['pages/index', 'pages/index/index'], mergePages = true, dir = 'src/pages', subPackages = [], @@ -28,9 +28,10 @@ export function resolveOptions(userOptions: UserOptions, viteRoot?: string): Res const root = viteRoot || slash(process.cwd()) const resolvedDirs = resolvePageDirs(dir, root, exclude) const resolvedSubDirs = subPackages.map(dir => slash(dir)) + const ResolvedHomePage = typeof homePage === 'string' ? [homePage] : homePage const resolvedOptions: ResolvedOptions = { - homePage, + homePage: ResolvedHomePage, mergePages, dirs: resolvedDirs, subPackages: resolvedSubDirs, diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index bdd0149..5351674 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -12,7 +12,7 @@ export type debugType = keyof typeof debug export interface Options { /** * The default application entry page is the home page - * @default 'pages/index' + * @default 'pages/index' or 'pages/index/index' */ homePage: string @@ -75,7 +75,7 @@ export interface Options { export type UserOptions = Partial -export interface ResolvedOptions extends Omit { +export interface ResolvedOptions extends Omit { /** * Resolves to the `root` value from Vite config. * @default config.root @@ -86,7 +86,10 @@ export interface ResolvedOptions extends Omit { * Resolved page dirs */ dirs: string[] - + /** + * Resolved entry page + */ + homePage: string[] } export interface PagePath {