{"id":13692008,"url":"https://github.com/uni-helper/vite-plugin-uni-pages","last_synced_at":"2025-05-16T02:07:15.007Z","repository":{"id":63221938,"uuid":"565729907","full_name":"uni-helper/vite-plugin-uni-pages","owner":"uni-helper","description":"为 Vite 下的 uni-app 提供基于文件系统的路由","archived":false,"fork":false,"pushed_at":"2025-04-26T15:16:37.000Z","size":1003,"stargazers_count":156,"open_issues_count":22,"forks_count":17,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-26T16:23:56.747Z","etag":null,"topics":["uniapp"],"latest_commit_sha":null,"homepage":"https://uni-helper.js.org/vite-plugin-uni-pages","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uni-helper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["ModyQyW","KeJunMao","Neil Lee"],"custom":["https://afdian.net/a/kejun","https://github.com/ModyQyW/sponsors","https://afdian.net/a/zguolee"]}},"created_at":"2022-11-14T07:52:00.000Z","updated_at":"2025-04-18T02:48:56.000Z","dependencies_parsed_at":"2023-09-26T23:41:46.870Z","dependency_job_id":"89eead63-fa1a-49b5-9656-2955897db938","html_url":"https://github.com/uni-helper/vite-plugin-uni-pages","commit_stats":{"total_commits":215,"total_committers":16,"mean_commits":13.4375,"dds":0.5209302325581395,"last_synced_commit":"e7b32138b28777bc89952f4824f2cc866b2f216b"},"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uni-helper%2Fvite-plugin-uni-pages","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uni-helper%2Fvite-plugin-uni-pages/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uni-helper%2Fvite-plugin-uni-pages/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uni-helper%2Fvite-plugin-uni-pages/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uni-helper","download_url":"https://codeload.github.com/uni-helper/vite-plugin-uni-pages/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254453651,"owners_count":22073617,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["uniapp"],"created_at":"2024-08-02T17:00:52.485Z","updated_at":"2025-05-16T02:07:14.989Z","avatar_url":"https://github.com/uni-helper.png","language":"TypeScript","funding_links":["https://github.com/sponsors/ModyQyW","https://github.com/sponsors/KeJunMao","https://github.com/sponsors/Neil Lee","https://afdian.net/a/kejun","https://github.com/ModyQyW/sponsors","https://afdian.net/a/zguolee"],"categories":["打包器插件"],"sub_categories":[],"readme":"# @uni-helper/vite-plugin-uni-pages\n\n在 Vite 驱动的 uni-app 上使用基于文件的路由系统。\n\n\u003ca href=\"https://www.npmjs.com/package/@uni-helper/vite-plugin-uni-pages\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@uni-helper/vite-plugin-uni-pages\" alt=\"NPM version\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## Packages\n\n- [vite-plugin-uni-pages](./packages/core/)\n\n  核心，提供基于文件的路由系统\n- [volar-service-uni-pages](./packages/volar/)\n\n  为 `\u003croute\u003e` 块 提供 IntelliSense\n- [pages-json-schema](./packages/schema/)\n\n  为 uni-app 的 `pages.json` 提供 schema\n\n## 安装\n\n```bash\npnpm i -D @uni-helper/vite-plugin-uni-pages\n```\n\n## 使用\n\n```ts\n// vite.config.ts\nimport { defineConfig } from 'vite'\nimport Uni from '@dcloudio/vite-plugin-uni'\nimport UniPages from '@uni-helper/vite-plugin-uni-pages'\n\n// It is recommended to put it in front of Uni\nexport default defineConfig({\n  plugins: [UniPages(), Uni()],\n})\n```\n\n在 `pages.config.(ts|mts|cts|js|cjs|mjs|json)` 定义全局属性，你可以在文件中使用 `#ifdef H5` 类似语法。\n\n```ts\n// pages.config.ts\nimport { defineUniPages } from '@uni-helper/vite-plugin-uni-pages'\n\nexport default defineUniPages({\n  // 你也可以定义 pages 字段，它具有最高的优先级。\n  pages: [],\n  globalStyle: {\n    navigationBarTextStyle: 'black',\n    navigationBarTitleText: '@uni-helper',\n  },\n})\n```\n\n现在所有的 page 都会被自动发现！\n\n### SFC 自定义块用于路由数据\n\n通过添加一个 `\u003croute\u003e` 块到 SFC 中来添加路由元数据。这将会在路由生成后直接添加到路由中，并且会覆盖。\n\n你可以使用 `\u003croute lang=\"yaml\"\u003e` 来指定一个解析器，或者使用 `routeBlockLang` 选项来设置一个默认的解析器。\n\n- **解析器支持：** JSON, JSON5, YAML\n- **默认：** JSON5\n\n```html\n\u003c!-- index.vue --\u003e\n\u003c!-- 使用 type=\"home\" 属性设置首页 --\u003e\n\u003croute type=\"home\" lang=\"json\"\u003e\n{\n  \"style\": { \"navigationBarTitleText\": \"@uni-helper\" }\n}\n\u003c/route\u003e\n\n\u003c!-- other.vue --\u003e\n\u003croute lang=\"yaml\"\u003e\nstyle:\n  navigationBarTitleText: \"@uni-helper\"\n\u003c/route\u003e\n```\n\n导入虚拟模块即可访问所有页面的元数据\n\n```ts\n/// \u003creference types=\"@uni-helper/vite-plugin-uni-pages/client\" /\u003e\nimport { pages } from 'virtual:uni-pages'\n\nconsole.log(pages)\n```\n\n## 配置\n\n```ts\nexport interface Options {\n  /**\n   * 为页面路径生成 TypeScript 声明\n   *\n   * 接受布尔值或与相对项目根目录的路径\n   *\n   * 默认为 uni-pages.d.ts\n   *\n   * @default true\n   */\n  dts?: boolean | string\n\n  /**\n   * 配置文件\n   * @default 'pages.config.(ts|mts|cts|js|cjs|mjs|json)',\n   */\n  configSource: ConfigSource\n\n  /**\n   * 设置默认路由入口\n   * @default 'pages/index' || 'pages/index/index'\n   */\n  homePage: string\n\n  /**\n   * 是否扫描并合并 pages.json 中 pages 字段\n   * @default true\n   */\n  mergePages: boolean\n\n  /**\n   * 扫描的目录\n   * @default 'src/pages'\n   */\n  dir: string\n\n  /**\n   * subPackages 扫描的目录，例如：src/pages-sub\n   */\n  subPackages: string[]\n\n  /**\n   * 输出 pages.json 目录\n   * @default \"src\"\n   */\n  outDir: string\n\n  /**\n   * 排除的页面，相对于 dir 和 subPackages\n   * @default []\n   * @example ['**/components/**/*.*']\n   */\n  exclude: string[]\n\n  /**\n   * 自定义块语言\n   * @default 'json5'\n   */\n  routeBlockLang: 'json5' | 'json' | 'yaml' | 'yml'\n\n  onBeforeLoadUserConfig: (ctx: PageContext) =\u003e void\n  onAfterLoadUserConfig: (ctx: PageContext) =\u003e void\n  onBeforeScanPages: (ctx: PageContext) =\u003e void\n  onAfterScanPages: (ctx: PageContext) =\u003e void\n  onBeforeMergePageMetaData: (ctx: PageContext) =\u003e void\n  onAfterMergePageMetaData: (ctx: PageContext) =\u003e void\n  onBeforeWriteFile: (ctx: PageContext) =\u003e void\n  onAfterWriteFile: (ctx: PageContext) =\u003e void\n}\n```\n\n## 感谢\n\n- [vite-plugin-pages](https://github.com/hannoeru/vite-plugin-pages.git)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funi-helper%2Fvite-plugin-uni-pages","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funi-helper%2Fvite-plugin-uni-pages","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funi-helper%2Fvite-plugin-uni-pages/lists"}