@uni-helper/vite-plugin-uni-pages 0.1.3 → 0.1.5

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.cjs CHANGED
@@ -65,6 +65,13 @@ function mergePageMetaDataArray(pageMetaData) {
65
65
  }
66
66
  return result;
67
67
  }
68
+ const getPagesConfigSourcePaths = async () => {
69
+ return await fg("pages.config.(ts|mts|cts|js|cjs|mjs|json)", {
70
+ deep: 0,
71
+ onlyFiles: true,
72
+ absolute: true
73
+ });
74
+ };
68
75
 
69
76
  function resolveOptions(userOptions, viteRoot) {
70
77
  const {
@@ -250,7 +257,11 @@ class PageContext {
250
257
  this._server = server;
251
258
  this.setupWatcher(server.watcher);
252
259
  }
253
- setupWatcher(watcher) {
260
+ async setupWatcher(watcher) {
261
+ if (process.env.UNI_PLATFORM !== "h5") {
262
+ const configs = await getPagesConfigSourcePaths();
263
+ watcher.add(configs);
264
+ }
254
265
  watcher.on("add", async (path2) => {
255
266
  path2 = slash(path2);
256
267
  if (!isTargetFile(path2))
@@ -392,6 +403,7 @@ exports.default = VitePluginUniPages;
392
403
  exports.defineUniPages = defineUniPages;
393
404
  exports.extsToGlob = extsToGlob;
394
405
  exports.getPageFiles = getPageFiles;
406
+ exports.getPagesConfigSourcePaths = getPagesConfigSourcePaths;
395
407
  exports.getRouteBlock = getRouteBlock;
396
408
  exports.invalidatePagesModule = invalidatePagesModule;
397
409
  exports.isConfigFile = isConfigFile;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Logger, ViteDevServer, Plugin } from 'vite';
2
- import { FSWatcher } from 'fs';
2
+ import { FSWatcher } from 'chokidar';
3
3
  import Debug from 'debug';
4
4
  import { SFCDescriptor, SFCBlock } from '@vue/compiler-sfc';
5
5
 
@@ -9,6 +9,7 @@ interface EasyCom {
9
9
  }
10
10
 
11
11
  type HEXColor = `#${string}`;
12
+ type ThemeColor = `@${string}`;
12
13
 
13
14
  interface AppPlus {
14
15
  /**
@@ -123,7 +124,7 @@ interface GlobalStyle {
123
124
  * @default "#F7F7F7"
124
125
  * @desc APP与H5为#F7F7F7,小程序平台请参考相应小程序文档
125
126
  */
126
- navigationBarBackgroundColor?: HEXColor;
127
+ navigationBarBackgroundColor?: HEXColor | ThemeColor;
127
128
  /**
128
129
  * 导航栏标题颜色及状态栏前景颜色,仅支持 black/white
129
130
  * @default "white"
@@ -146,7 +147,7 @@ interface GlobalStyle {
146
147
  * @default "#ffffff"
147
148
  * @desc 微信小程序
148
149
  */
149
- backgroundColor?: HEXColor;
150
+ backgroundColor?: HEXColor | ThemeColor;
150
151
  /**
151
152
  * 下拉 loading 的样式,仅支持 dark / light
152
153
  * @default "dark"
@@ -170,13 +171,13 @@ interface GlobalStyle {
170
171
  * @default "#ffffff"
171
172
  * @desc 仅 iOS 平台
172
173
  */
173
- backgroundColorTop?: HEXColor;
174
+ backgroundColorTop?: HEXColor | ThemeColor;
174
175
  /**
175
176
  * 底部窗口的背景色(bounce回弹区域)
176
177
  * @default "#ffffff"
177
178
  * @desc 仅 iOS 平台
178
179
  */
179
- backgroundColorBottom?: HEXColor;
180
+ backgroundColorBottom?: HEXColor | ThemeColor;
180
181
  /**
181
182
  * 导航栏图片地址(替换当前文字标题),支付宝小程序内必须使用https的图片链接地址
182
183
  * @desc 支付宝小程序、H5、APP
@@ -513,6 +514,22 @@ interface PreloadRule {
513
514
  */
514
515
  network?: string;
515
516
  }
517
+ interface UniIdRouter {
518
+ /**
519
+ * 登录页面路径
520
+ */
521
+ loginPage: string;
522
+ /**
523
+ * 需要登录才可以访问的页面列表,可以使用正则语法
524
+ */
525
+ needLogin: string[];
526
+ /**
527
+ * 是否自动解析云对象及 clientDB 的错误码,如果是客户端 token 不正确或 token 过期则自动跳转配置的登录页面
528
+ *
529
+ * @default true
530
+ */
531
+ resToLogin?: boolean;
532
+ }
516
533
  interface SubPackage {
517
534
  /**
518
535
  * 子包的根目录
@@ -577,7 +594,9 @@ interface PagesConfig {
577
594
  * 分包预下载规则
578
595
  * @desc 微信小程序
579
596
  */
580
- preloadRule?: PreloadRule;
597
+ preloadRule?: {
598
+ [path: string]: PreloadRule;
599
+ };
581
600
  /**
582
601
  * `Worker` 代码放置的目录
583
602
  * @desc 微信小程序
@@ -599,9 +618,13 @@ interface PagesConfig {
599
618
  */
600
619
  rightWindow?: TheWindow;
601
620
  /**
602
- * 自动跳转相关配置,新增于HBuilderX 3.5.0
621
+ * 自动跳转相关配置,新增于 HBuilderX 3.5.0
603
622
  */
604
- uniIdRouter?: any;
623
+ uniIdRouter?: UniIdRouter;
624
+ /**
625
+ * 默认启动首页,新增于 HBuilderX 3.7.0
626
+ */
627
+ entryPagePath?: string;
605
628
  [x: string]: any;
606
629
  }
607
630
  interface UserPagesConfig extends PagesConfig {
@@ -624,7 +647,7 @@ declare class PageContext {
624
647
  loadUserPagesConfig(): Promise<void>;
625
648
  scanPages(): Promise<void>;
626
649
  setupViteServer(server: ViteDevServer): void;
627
- setupWatcher(watcher: FSWatcher): void;
650
+ setupWatcher(watcher: FSWatcher): Promise<void>;
628
651
  onUpdate(): void;
629
652
  parsePage(page: PagePath): Promise<PageMetaDatum>;
630
653
  mergePageMetaData(): Promise<void>;
@@ -698,6 +721,10 @@ interface PageMetaDatum {
698
721
  * 配置页面窗口表现,配置项参考下方 pageStyle
699
722
  */
700
723
  style?: GlobalStyle;
724
+ /**
725
+ * 当前页面是否需要登录才可以访问,此配置优先级高于 uniIdRouter 下的 needLogin
726
+ */
727
+ needLogin?: boolean;
701
728
  [x: string]: any;
702
729
  }
703
730
 
@@ -723,6 +750,7 @@ declare function isConfigFile(path: string): boolean;
723
750
  * TODO: support merge middleware
724
751
  */
725
752
  declare function mergePageMetaDataArray(pageMetaData: PageMetaDatum[]): PageMetaDatum[];
753
+ declare const getPagesConfigSourcePaths: () => Promise<string[]>;
726
754
 
727
755
  /**
728
756
  * Resolves the files that are valid pages for the given context.
@@ -743,4 +771,4 @@ declare function getRouteBlock(path: string, options: ResolvedOptions): Promise<
743
771
 
744
772
  declare const VitePluginUniPages: (userOptions?: UserOptions) => Plugin;
745
773
 
746
- export { Condition, ConditionItem, CustomBlock, EasyCom, FILE_EXTENSIONS, GlobalStyle, IconFont, MODULE_ID_VIRTUAL, MidButton, OUTPUT_NAME, Options, PageContext, PageMetaDatum, PagePath, PagesConfig, PreloadRule, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPackage, TabBar, TabBarItem, TheWindow, UserOptions, UserPagesConfig, VitePluginUniPages, checkPagesJsonFile, debug, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getRouteBlock, invalidatePagesModule, isConfigFile, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, writeFileSync };
774
+ export { Condition, ConditionItem, CustomBlock, EasyCom, FILE_EXTENSIONS, GlobalStyle, IconFont, MODULE_ID_VIRTUAL, MidButton, OUTPUT_NAME, Options, PageContext, PageMetaDatum, PagePath, PagesConfig, PreloadRule, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPackage, TabBar, TabBarItem, TheWindow, UniIdRouter, UserOptions, UserPagesConfig, VitePluginUniPages, checkPagesJsonFile, debug, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getPagesConfigSourcePaths, getRouteBlock, invalidatePagesModule, isConfigFile, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, writeFileSync };
package/dist/index.mjs CHANGED
@@ -61,6 +61,13 @@ function mergePageMetaDataArray(pageMetaData) {
61
61
  }
62
62
  return result;
63
63
  }
64
+ const getPagesConfigSourcePaths = async () => {
65
+ return await fg("pages.config.(ts|mts|cts|js|cjs|mjs|json)", {
66
+ deep: 0,
67
+ onlyFiles: true,
68
+ absolute: true
69
+ });
70
+ };
64
71
 
65
72
  function resolveOptions(userOptions, viteRoot) {
66
73
  const {
@@ -246,7 +253,11 @@ class PageContext {
246
253
  this._server = server;
247
254
  this.setupWatcher(server.watcher);
248
255
  }
249
- setupWatcher(watcher) {
256
+ async setupWatcher(watcher) {
257
+ if (process.env.UNI_PLATFORM !== "h5") {
258
+ const configs = await getPagesConfigSourcePaths();
259
+ watcher.add(configs);
260
+ }
250
261
  watcher.on("add", async (path2) => {
251
262
  path2 = slash(path2);
252
263
  if (!isTargetFile(path2))
@@ -376,4 +387,4 @@ const VitePluginUniPages = (userOptions = {}) => {
376
387
  };
377
388
  };
378
389
 
379
- export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, checkPagesJsonFile, debug, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getRouteBlock, invalidatePagesModule, isConfigFile, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, writeFileSync };
390
+ export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, checkPagesJsonFile, debug, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getPagesConfigSourcePaths, getRouteBlock, invalidatePagesModule, isConfigFile, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, writeFileSync };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uni-helper/vite-plugin-uni-pages",
3
3
  "type": "module",
4
- "version": "0.1.3",
4
+ "version": "0.1.5",
5
5
  "packageManager": "pnpm@7.16.1",
6
6
  "description": "File system based routing for uni-app applications using Vite",
7
7
  "author": "KeJun",