@uni-helper/vite-plugin-uni-pages 0.2.9 → 0.2.11

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/client.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- declare module "virtual:uni-pages" {
2
- import { PageMetaDatum } from "./src/types";
3
- import { SubPackage } from "./src/config/types/index";
4
- export const pages: PageMetaDatum[];
5
- export const subPackages: SubPackage[];
1
+ declare module 'virtual:uni-pages' {
2
+ import type { PageMetaDatum } from './src/types'
3
+ import type { SubPackage } from './src/config/types/index'
4
+
5
+ export const pages: PageMetaDatum[]
6
+ export const subPackages: SubPackage[]
6
7
  }
package/dist/index.cjs CHANGED
@@ -9,15 +9,14 @@ const vite = require('vite');
9
9
  const MagicString = require('magic-string');
10
10
  const chokidar = require('chokidar');
11
11
  const unconfig = require('unconfig');
12
- const uniEnv = require('@uni-helper/uni-env');
13
12
  const Debug = require('debug');
14
13
  const fs = require('node:fs');
15
14
  const promises = require('node:fs/promises');
16
15
  const lodashUnified = require('lodash-unified');
17
- const fg = require('fast-glob');
18
16
  const JSON5 = require('json5');
19
17
  const yaml = require('yaml');
20
18
  const compilerSfc = require('@vue/compiler-sfc');
19
+ const fg = require('fast-glob');
21
20
 
22
21
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
23
22
 
@@ -27,8 +26,8 @@ const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
27
26
  const chokidar__default = /*#__PURE__*/_interopDefaultCompat(chokidar);
28
27
  const Debug__default = /*#__PURE__*/_interopDefaultCompat(Debug);
29
28
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
30
- const fg__default = /*#__PURE__*/_interopDefaultCompat(fg);
31
29
  const JSON5__default = /*#__PURE__*/_interopDefaultCompat(JSON5);
30
+ const fg__default = /*#__PURE__*/_interopDefaultCompat(fg);
32
31
 
33
32
  function slash(str) {
34
33
  return str.replace(/\\/g, "/");
@@ -178,9 +177,6 @@ function isTargetFile(path) {
178
177
  const ext = path.split(".").pop();
179
178
  return FILE_EXTENSIONS.includes(ext);
180
179
  }
181
- function isConfigFile(path) {
182
- return path.includes("pages.config");
183
- }
184
180
  function mergePageMetaDataArray(pageMetaData) {
185
181
  const pageMetaDataObj = lodashUnified.groupBy(pageMetaData, "path");
186
182
  const result = [];
@@ -195,13 +191,6 @@ function mergePageMetaDataArray(pageMetaData) {
195
191
  }
196
192
  return result;
197
193
  }
198
- async function getPagesConfigSourcePaths(configSource) {
199
- return await fg__default(configSource.map((v) => v.files).flat(), {
200
- deep: 0,
201
- onlyFiles: true,
202
- absolute: true
203
- });
204
- }
205
194
  function useCachedPages() {
206
195
  const pages = /* @__PURE__ */ new Map();
207
196
  function parseData(block) {
@@ -328,6 +317,7 @@ class PageContext {
328
317
  constructor(userOptions, viteRoot = process__default.cwd()) {
329
318
  __publicField(this, "_server");
330
319
  __publicField(this, "pagesGlobConfig");
320
+ __publicField(this, "pagesConfigSourcePaths", []);
331
321
  __publicField(this, "pagesPath", []);
332
322
  __publicField(this, "subPagesPath", {});
333
323
  __publicField(this, "pageMetaData", []);
@@ -354,9 +344,10 @@ class PageContext {
354
344
  this.logger = logger;
355
345
  }
356
346
  async loadUserPagesConfig() {
357
- const sources = this.options.configSource;
358
- const { config } = await unconfig.loadConfig({ cwd: this.root, sources, defaults: {} });
347
+ const configSource = this.options.configSource;
348
+ const { config, sources } = await unconfig.loadConfig({ cwd: this.root, sources: configSource, defaults: {} });
359
349
  this.pagesGlobConfig = config;
350
+ this.pagesConfigSourcePaths = sources;
360
351
  debug.options(config);
361
352
  }
362
353
  async scanPages() {
@@ -382,10 +373,7 @@ class PageContext {
382
373
  this.setupWatcher(server.watcher);
383
374
  }
384
375
  async setupWatcher(watcher) {
385
- if (!uniEnv.isH5) {
386
- const configs = await getPagesConfigSourcePaths(this.options.configSource);
387
- watcher.add(configs);
388
- }
376
+ watcher.add(this.pagesConfigSourcePaths);
389
377
  const targetDirs = [...this.options.dirs, ...this.options.subPackages].map((v) => slash(path__default.resolve(this.root, v)));
390
378
  const isInTargetDirs = (filePath) => targetDirs.some((v) => slash(path__default.resolve(this.root, filePath)).startsWith(v));
391
379
  watcher.on("add", async (path2) => {
@@ -400,7 +388,7 @@ class PageContext {
400
388
  });
401
389
  watcher.on("change", async (path2) => {
402
390
  path2 = slash(path2);
403
- if (!isTargetFile(path2) && !isConfigFile(path2))
391
+ if (!isTargetFile(path2))
404
392
  return;
405
393
  if (!isInTargetDirs(path2))
406
394
  return;
@@ -410,6 +398,13 @@ class PageContext {
410
398
  if (await this.updatePagesJSON(path2))
411
399
  this.onUpdate();
412
400
  });
401
+ watcher.on("change", async (path2) => {
402
+ if (this.pagesConfigSourcePaths.includes(path2)) {
403
+ debug.pages(`Config source changed: ${path2}`);
404
+ if (await this.updatePagesJSON())
405
+ this.onUpdate();
406
+ }
407
+ });
413
408
  watcher.on("unlink", async (path2) => {
414
409
  path2 = slash(path2);
415
410
  if (!isTargetFile(path2))
@@ -664,11 +659,9 @@ exports.default = VitePluginUniPages;
664
659
  exports.defineUniPages = defineUniPages;
665
660
  exports.extsToGlob = extsToGlob;
666
661
  exports.getPageFiles = getPageFiles;
667
- exports.getPagesConfigSourcePaths = getPagesConfigSourcePaths;
668
662
  exports.getRouteBlock = getRouteBlock;
669
663
  exports.getRouteSfcBlock = getRouteSfcBlock;
670
664
  exports.invalidatePagesModule = invalidatePagesModule;
671
- exports.isConfigFile = isConfigFile;
672
665
  exports.isTargetFile = isTargetFile;
673
666
  exports.mergePageMetaDataArray = mergePageMetaDataArray;
674
667
  exports.parseCustomBlock = parseCustomBlock;
package/dist/index.d.cts CHANGED
@@ -224,7 +224,7 @@ interface GlobalStyle {
224
224
  'app-plus'?: AppPlus;
225
225
  /**
226
226
  * 设置编译到 H5 平台的特定样式,配置项参考下方 H5
227
- * @type H5
227
+ * @type {H5}
228
228
  * @desc H5
229
229
  */
230
230
  h5?: H5;
@@ -270,7 +270,7 @@ interface GlobalStyle {
270
270
  'mp-jd'?: object;
271
271
  /**
272
272
  * 引用小程序组件,参考 小程序组件
273
- * @type Record<string, string>
273
+ * @type {Record<string, string>}
274
274
  * @desc
275
275
  */
276
276
  usingComponents?: Record<string, string>;
@@ -441,9 +441,9 @@ interface TabBar {
441
441
  blurEffect?: string;
442
442
  /**
443
443
  * tab 的列表,详见 list 属性说明,最少2个、最多5个 tab
444
- * @type TabBarItem[]
444
+ * @type {TabBarItem[]}
445
445
  */
446
- list?: TabBarItem[];
446
+ list: [TabBarItem, TabBarItem, TabBarItem?, TabBarItem?, TabBarItem?];
447
447
  /**
448
448
  * 可选值 bottom、top
449
449
  * @default "bottom"
@@ -639,6 +639,7 @@ declare function defineUniPages(config: UserPagesConfig): UserPagesConfig;
639
639
  declare class PageContext {
640
640
  private _server;
641
641
  pagesGlobConfig: PagesConfig | undefined;
642
+ pagesConfigSourcePaths: string[];
642
643
  pagesPath: PagePath[];
643
644
  subPagesPath: Record<string, PagePath[]>;
644
645
  pageMetaData: PageMetaDatum[];
@@ -681,14 +682,12 @@ declare const debug: {
681
682
  };
682
683
  declare function extsToGlob(extensions: string[]): string;
683
684
  declare function isTargetFile(path: string): boolean;
684
- declare function isConfigFile(path: string): boolean;
685
685
  /**
686
686
  * merge page meta data array by path and assign style
687
687
  * @param pageMetaData page meta data array
688
688
  * TODO: support merge middleware
689
689
  */
690
690
  declare function mergePageMetaDataArray(pageMetaData: PageMetaDatum[]): PageMetaDatum[];
691
- declare function getPagesConfigSourcePaths(configSource: LoadConfigSource<PagesConfig>[]): Promise<string[]>;
692
691
  declare function useCachedPages(): {
693
692
  setCache: (filePath: string, routeBlock?: SFCBlock) => void;
694
693
  hasChanged: (filePath: string, routeBlock?: SFCBlock) => Promise<boolean>;
@@ -812,7 +811,7 @@ interface SubPageMetaDatum {
812
811
  }
813
812
 
814
813
  declare const MODULE_ID_VIRTUAL = "virtual:uni-pages";
815
- declare const RESOLVED_MODULE_ID_VIRTUAL: string;
814
+ declare const RESOLVED_MODULE_ID_VIRTUAL = "\0virtual:uni-pages";
816
815
  declare const OUTPUT_NAME = "pages.json";
817
816
  declare const FILE_EXTENSIONS: string[];
818
817
 
@@ -836,4 +835,4 @@ declare function getRouteBlock(path: string, blockStr: SFCBlock | undefined, opt
836
835
 
837
836
  declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
838
837
 
839
- export { type Condition, type ConditionItem, type ConfigSource, type CustomBlock, type EasyCom, FILE_EXTENSIONS, type GlobalStyle, type IconFont, MODULE_ID_VIRTUAL, type MidButton, OUTPUT_NAME, type Options, PageContext, type PageMetaDatum, type PagePath, type PagesConfig, type PreloadRule, RESOLVED_MODULE_ID_VIRTUAL, type ResolvedOptions, type SubPackage, type SubPageMetaDatum, type TabBar, type TabBarItem, type TheWindow, type UniIdRouter, type UserOptions, type UserPagesConfig, VitePluginUniPages, checkPagesJsonFile, debug, type debugType, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getPagesConfigSourcePaths, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isConfigFile, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, useCachedPages, writeFileSync };
838
+ export { type Condition, type ConditionItem, type ConfigSource, type CustomBlock, type EasyCom, FILE_EXTENSIONS, type GlobalStyle, type IconFont, MODULE_ID_VIRTUAL, type MidButton, OUTPUT_NAME, type Options, PageContext, type PageMetaDatum, type PagePath, type PagesConfig, type PreloadRule, RESOLVED_MODULE_ID_VIRTUAL, type ResolvedOptions, type SubPackage, type SubPageMetaDatum, type TabBar, type TabBarItem, type TheWindow, type UniIdRouter, type UserOptions, type UserPagesConfig, VitePluginUniPages, checkPagesJsonFile, debug, type debugType, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, useCachedPages, writeFileSync };
package/dist/index.d.mts CHANGED
@@ -224,7 +224,7 @@ interface GlobalStyle {
224
224
  'app-plus'?: AppPlus;
225
225
  /**
226
226
  * 设置编译到 H5 平台的特定样式,配置项参考下方 H5
227
- * @type H5
227
+ * @type {H5}
228
228
  * @desc H5
229
229
  */
230
230
  h5?: H5;
@@ -270,7 +270,7 @@ interface GlobalStyle {
270
270
  'mp-jd'?: object;
271
271
  /**
272
272
  * 引用小程序组件,参考 小程序组件
273
- * @type Record<string, string>
273
+ * @type {Record<string, string>}
274
274
  * @desc
275
275
  */
276
276
  usingComponents?: Record<string, string>;
@@ -441,9 +441,9 @@ interface TabBar {
441
441
  blurEffect?: string;
442
442
  /**
443
443
  * tab 的列表,详见 list 属性说明,最少2个、最多5个 tab
444
- * @type TabBarItem[]
444
+ * @type {TabBarItem[]}
445
445
  */
446
- list?: TabBarItem[];
446
+ list: [TabBarItem, TabBarItem, TabBarItem?, TabBarItem?, TabBarItem?];
447
447
  /**
448
448
  * 可选值 bottom、top
449
449
  * @default "bottom"
@@ -639,6 +639,7 @@ declare function defineUniPages(config: UserPagesConfig): UserPagesConfig;
639
639
  declare class PageContext {
640
640
  private _server;
641
641
  pagesGlobConfig: PagesConfig | undefined;
642
+ pagesConfigSourcePaths: string[];
642
643
  pagesPath: PagePath[];
643
644
  subPagesPath: Record<string, PagePath[]>;
644
645
  pageMetaData: PageMetaDatum[];
@@ -681,14 +682,12 @@ declare const debug: {
681
682
  };
682
683
  declare function extsToGlob(extensions: string[]): string;
683
684
  declare function isTargetFile(path: string): boolean;
684
- declare function isConfigFile(path: string): boolean;
685
685
  /**
686
686
  * merge page meta data array by path and assign style
687
687
  * @param pageMetaData page meta data array
688
688
  * TODO: support merge middleware
689
689
  */
690
690
  declare function mergePageMetaDataArray(pageMetaData: PageMetaDatum[]): PageMetaDatum[];
691
- declare function getPagesConfigSourcePaths(configSource: LoadConfigSource<PagesConfig>[]): Promise<string[]>;
692
691
  declare function useCachedPages(): {
693
692
  setCache: (filePath: string, routeBlock?: SFCBlock) => void;
694
693
  hasChanged: (filePath: string, routeBlock?: SFCBlock) => Promise<boolean>;
@@ -812,7 +811,7 @@ interface SubPageMetaDatum {
812
811
  }
813
812
 
814
813
  declare const MODULE_ID_VIRTUAL = "virtual:uni-pages";
815
- declare const RESOLVED_MODULE_ID_VIRTUAL: string;
814
+ declare const RESOLVED_MODULE_ID_VIRTUAL = "\0virtual:uni-pages";
816
815
  declare const OUTPUT_NAME = "pages.json";
817
816
  declare const FILE_EXTENSIONS: string[];
818
817
 
@@ -836,4 +835,4 @@ declare function getRouteBlock(path: string, blockStr: SFCBlock | undefined, opt
836
835
 
837
836
  declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
838
837
 
839
- export { type Condition, type ConditionItem, type ConfigSource, type CustomBlock, type EasyCom, FILE_EXTENSIONS, type GlobalStyle, type IconFont, MODULE_ID_VIRTUAL, type MidButton, OUTPUT_NAME, type Options, PageContext, type PageMetaDatum, type PagePath, type PagesConfig, type PreloadRule, RESOLVED_MODULE_ID_VIRTUAL, type ResolvedOptions, type SubPackage, type SubPageMetaDatum, type TabBar, type TabBarItem, type TheWindow, type UniIdRouter, type UserOptions, type UserPagesConfig, VitePluginUniPages, checkPagesJsonFile, debug, type debugType, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getPagesConfigSourcePaths, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isConfigFile, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, useCachedPages, writeFileSync };
838
+ export { type Condition, type ConditionItem, type ConfigSource, type CustomBlock, type EasyCom, FILE_EXTENSIONS, type GlobalStyle, type IconFont, MODULE_ID_VIRTUAL, type MidButton, OUTPUT_NAME, type Options, PageContext, type PageMetaDatum, type PagePath, type PagesConfig, type PreloadRule, RESOLVED_MODULE_ID_VIRTUAL, type ResolvedOptions, type SubPackage, type SubPageMetaDatum, type TabBar, type TabBarItem, type TheWindow, type UniIdRouter, type UserOptions, type UserPagesConfig, VitePluginUniPages, checkPagesJsonFile, debug, type debugType, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, useCachedPages, writeFileSync };
package/dist/index.d.ts CHANGED
@@ -224,7 +224,7 @@ interface GlobalStyle {
224
224
  'app-plus'?: AppPlus;
225
225
  /**
226
226
  * 设置编译到 H5 平台的特定样式,配置项参考下方 H5
227
- * @type H5
227
+ * @type {H5}
228
228
  * @desc H5
229
229
  */
230
230
  h5?: H5;
@@ -270,7 +270,7 @@ interface GlobalStyle {
270
270
  'mp-jd'?: object;
271
271
  /**
272
272
  * 引用小程序组件,参考 小程序组件
273
- * @type Record<string, string>
273
+ * @type {Record<string, string>}
274
274
  * @desc
275
275
  */
276
276
  usingComponents?: Record<string, string>;
@@ -441,9 +441,9 @@ interface TabBar {
441
441
  blurEffect?: string;
442
442
  /**
443
443
  * tab 的列表,详见 list 属性说明,最少2个、最多5个 tab
444
- * @type TabBarItem[]
444
+ * @type {TabBarItem[]}
445
445
  */
446
- list?: TabBarItem[];
446
+ list: [TabBarItem, TabBarItem, TabBarItem?, TabBarItem?, TabBarItem?];
447
447
  /**
448
448
  * 可选值 bottom、top
449
449
  * @default "bottom"
@@ -639,6 +639,7 @@ declare function defineUniPages(config: UserPagesConfig): UserPagesConfig;
639
639
  declare class PageContext {
640
640
  private _server;
641
641
  pagesGlobConfig: PagesConfig | undefined;
642
+ pagesConfigSourcePaths: string[];
642
643
  pagesPath: PagePath[];
643
644
  subPagesPath: Record<string, PagePath[]>;
644
645
  pageMetaData: PageMetaDatum[];
@@ -681,14 +682,12 @@ declare const debug: {
681
682
  };
682
683
  declare function extsToGlob(extensions: string[]): string;
683
684
  declare function isTargetFile(path: string): boolean;
684
- declare function isConfigFile(path: string): boolean;
685
685
  /**
686
686
  * merge page meta data array by path and assign style
687
687
  * @param pageMetaData page meta data array
688
688
  * TODO: support merge middleware
689
689
  */
690
690
  declare function mergePageMetaDataArray(pageMetaData: PageMetaDatum[]): PageMetaDatum[];
691
- declare function getPagesConfigSourcePaths(configSource: LoadConfigSource<PagesConfig>[]): Promise<string[]>;
692
691
  declare function useCachedPages(): {
693
692
  setCache: (filePath: string, routeBlock?: SFCBlock) => void;
694
693
  hasChanged: (filePath: string, routeBlock?: SFCBlock) => Promise<boolean>;
@@ -812,7 +811,7 @@ interface SubPageMetaDatum {
812
811
  }
813
812
 
814
813
  declare const MODULE_ID_VIRTUAL = "virtual:uni-pages";
815
- declare const RESOLVED_MODULE_ID_VIRTUAL: string;
814
+ declare const RESOLVED_MODULE_ID_VIRTUAL = "\0virtual:uni-pages";
816
815
  declare const OUTPUT_NAME = "pages.json";
817
816
  declare const FILE_EXTENSIONS: string[];
818
817
 
@@ -836,4 +835,4 @@ declare function getRouteBlock(path: string, blockStr: SFCBlock | undefined, opt
836
835
 
837
836
  declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
838
837
 
839
- export { type Condition, type ConditionItem, type ConfigSource, type CustomBlock, type EasyCom, FILE_EXTENSIONS, type GlobalStyle, type IconFont, MODULE_ID_VIRTUAL, type MidButton, OUTPUT_NAME, type Options, PageContext, type PageMetaDatum, type PagePath, type PagesConfig, type PreloadRule, RESOLVED_MODULE_ID_VIRTUAL, type ResolvedOptions, type SubPackage, type SubPageMetaDatum, type TabBar, type TabBarItem, type TheWindow, type UniIdRouter, type UserOptions, type UserPagesConfig, VitePluginUniPages, checkPagesJsonFile, debug, type debugType, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getPagesConfigSourcePaths, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isConfigFile, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, useCachedPages, writeFileSync };
838
+ export { type Condition, type ConditionItem, type ConfigSource, type CustomBlock, type EasyCom, FILE_EXTENSIONS, type GlobalStyle, type IconFont, MODULE_ID_VIRTUAL, type MidButton, OUTPUT_NAME, type Options, PageContext, type PageMetaDatum, type PagePath, type PagesConfig, type PreloadRule, RESOLVED_MODULE_ID_VIRTUAL, type ResolvedOptions, type SubPackage, type SubPageMetaDatum, type TabBar, type TabBarItem, type TheWindow, type UniIdRouter, type UserOptions, type UserPagesConfig, VitePluginUniPages, checkPagesJsonFile, debug, type debugType, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, useCachedPages, writeFileSync };
package/dist/index.mjs CHANGED
@@ -5,15 +5,14 @@ import { normalizePath, createLogger } from 'vite';
5
5
  import MagicString from 'magic-string';
6
6
  import chokidar from 'chokidar';
7
7
  import { loadConfig } from 'unconfig';
8
- import { isH5 } from '@uni-helper/uni-env';
9
8
  import Debug from 'debug';
10
9
  import fs, { existsSync } from 'node:fs';
11
10
  import { readFile, mkdir, writeFile as writeFile$1 } from 'node:fs/promises';
12
11
  import { groupBy } from 'lodash-unified';
13
- import fg from 'fast-glob';
14
12
  import JSON5 from 'json5';
15
13
  import { parse as parse$1 } from 'yaml';
16
14
  import { parse } from '@vue/compiler-sfc';
15
+ import fg from 'fast-glob';
17
16
 
18
17
  function slash(str) {
19
18
  return str.replace(/\\/g, "/");
@@ -163,9 +162,6 @@ function isTargetFile(path) {
163
162
  const ext = path.split(".").pop();
164
163
  return FILE_EXTENSIONS.includes(ext);
165
164
  }
166
- function isConfigFile(path) {
167
- return path.includes("pages.config");
168
- }
169
165
  function mergePageMetaDataArray(pageMetaData) {
170
166
  const pageMetaDataObj = groupBy(pageMetaData, "path");
171
167
  const result = [];
@@ -180,13 +176,6 @@ function mergePageMetaDataArray(pageMetaData) {
180
176
  }
181
177
  return result;
182
178
  }
183
- async function getPagesConfigSourcePaths(configSource) {
184
- return await fg(configSource.map((v) => v.files).flat(), {
185
- deep: 0,
186
- onlyFiles: true,
187
- absolute: true
188
- });
189
- }
190
179
  function useCachedPages() {
191
180
  const pages = /* @__PURE__ */ new Map();
192
181
  function parseData(block) {
@@ -313,6 +302,7 @@ class PageContext {
313
302
  constructor(userOptions, viteRoot = process.cwd()) {
314
303
  __publicField(this, "_server");
315
304
  __publicField(this, "pagesGlobConfig");
305
+ __publicField(this, "pagesConfigSourcePaths", []);
316
306
  __publicField(this, "pagesPath", []);
317
307
  __publicField(this, "subPagesPath", {});
318
308
  __publicField(this, "pageMetaData", []);
@@ -339,9 +329,10 @@ class PageContext {
339
329
  this.logger = logger;
340
330
  }
341
331
  async loadUserPagesConfig() {
342
- const sources = this.options.configSource;
343
- const { config } = await loadConfig({ cwd: this.root, sources, defaults: {} });
332
+ const configSource = this.options.configSource;
333
+ const { config, sources } = await loadConfig({ cwd: this.root, sources: configSource, defaults: {} });
344
334
  this.pagesGlobConfig = config;
335
+ this.pagesConfigSourcePaths = sources;
345
336
  debug.options(config);
346
337
  }
347
338
  async scanPages() {
@@ -367,10 +358,7 @@ class PageContext {
367
358
  this.setupWatcher(server.watcher);
368
359
  }
369
360
  async setupWatcher(watcher) {
370
- if (!isH5) {
371
- const configs = await getPagesConfigSourcePaths(this.options.configSource);
372
- watcher.add(configs);
373
- }
361
+ watcher.add(this.pagesConfigSourcePaths);
374
362
  const targetDirs = [...this.options.dirs, ...this.options.subPackages].map((v) => slash(path.resolve(this.root, v)));
375
363
  const isInTargetDirs = (filePath) => targetDirs.some((v) => slash(path.resolve(this.root, filePath)).startsWith(v));
376
364
  watcher.on("add", async (path2) => {
@@ -385,7 +373,7 @@ class PageContext {
385
373
  });
386
374
  watcher.on("change", async (path2) => {
387
375
  path2 = slash(path2);
388
- if (!isTargetFile(path2) && !isConfigFile(path2))
376
+ if (!isTargetFile(path2))
389
377
  return;
390
378
  if (!isInTargetDirs(path2))
391
379
  return;
@@ -395,6 +383,13 @@ class PageContext {
395
383
  if (await this.updatePagesJSON(path2))
396
384
  this.onUpdate();
397
385
  });
386
+ watcher.on("change", async (path2) => {
387
+ if (this.pagesConfigSourcePaths.includes(path2)) {
388
+ debug.pages(`Config source changed: ${path2}`);
389
+ if (await this.updatePagesJSON())
390
+ this.onUpdate();
391
+ }
392
+ });
398
393
  watcher.on("unlink", async (path2) => {
399
394
  path2 = slash(path2);
400
395
  if (!isTargetFile(path2))
@@ -637,4 +632,4 @@ function VitePluginUniPages(userOptions = {}) {
637
632
  };
638
633
  }
639
634
 
640
- export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, checkPagesJsonFile, debug, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getPagesConfigSourcePaths, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isConfigFile, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, useCachedPages, writeFileSync };
635
+ export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, checkPagesJsonFile, debug, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, useCachedPages, 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.2.9",
4
+ "version": "0.2.11",
5
5
  "description": "File system based routing for uni-app applications using Vite",
6
6
  "author": "KeJun",
7
7
  "license": "MIT",
@@ -45,12 +45,12 @@
45
45
  "lodash-unified": "^1.0.3",
46
46
  "magic-string": "^0.30.3",
47
47
  "unconfig": "^0.3.10",
48
- "yaml": "^2.3.1"
48
+ "yaml": "^2.3.2"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@antfu/utils": "^0.7.6",
52
52
  "@types/debug": "^4.1.8",
53
- "@types/node": "^18.17.9"
53
+ "@types/node": "^18.17.18"
54
54
  },
55
55
  "scripts": {
56
56
  "build": "unbuild",