@uni-helper/vite-plugin-uni-pages 0.2.6 → 0.2.7

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.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Logger, ViteDevServer, Plugin } from 'vite';
2
+ import { LoadConfigSource } from 'unconfig';
2
3
  import { FSWatcher } from 'chokidar';
3
4
  import Debug from 'debug';
4
5
  import { SFCBlock, SFCDescriptor } from '@vue/compiler-sfc';
@@ -417,21 +418,21 @@ interface TabBar {
417
418
  /**
418
419
  * tab 上的文字默认颜色
419
420
  */
420
- color?: Color;
421
+ color?: Color | ThemeColor;
421
422
  /**
422
423
  * tab 上的文字选中时的颜色
423
424
  */
424
- selectedColor?: Color;
425
+ selectedColor?: Color | ThemeColor;
425
426
  /**
426
427
  * tab 的背景色
427
428
  */
428
- backgroundColor?: Color;
429
+ backgroundColor?: Color | ThemeColor;
429
430
  /**
430
431
  * tabbar 上边框的颜色,可选值 black/white,也支持其他颜色值
431
432
  * @default "black"
432
433
  * @desc App 2.3.4+ 、H5 3.0.0+
433
434
  */
434
- borderStyle?: string;
435
+ borderStyle?: string | ThemeColor;
435
436
  /**
436
437
  * iOS 高斯模糊效果,可选值 dark/extralight/light/none(参考?:使用说明)
437
438
  * @default "none"
@@ -685,7 +686,7 @@ declare function isConfigFile(path: string): boolean;
685
686
  * TODO: support merge middleware
686
687
  */
687
688
  declare function mergePageMetaDataArray(pageMetaData: PageMetaDatum[]): PageMetaDatum[];
688
- declare function getPagesConfigSourcePaths(): Promise<string[]>;
689
+ declare function getPagesConfigSourcePaths(configSource: LoadConfigSource<PagesConfig>[]): Promise<string[]>;
689
690
  declare function useCachedPages(): {
690
691
  setCache: (filePath: string, routeBlock?: SFCBlock) => void;
691
692
  hasChanged: (filePath: string, routeBlock?: SFCBlock) => Promise<boolean>;
@@ -696,7 +697,14 @@ interface CustomBlock {
696
697
  content: Record<string, any>;
697
698
  }
698
699
  type debugType = keyof typeof debug;
700
+ type ConfigSource = string | LoadConfigSource<PagesConfig> | LoadConfigSource<PagesConfig>[];
699
701
  interface Options {
702
+ /**
703
+ * Load from configs files
704
+ *
705
+ * @default 'pages.config.(ts|mts|cts|js|cjs|mjs|json)',
706
+ */
707
+ configSource: ConfigSource;
700
708
  /**
701
709
  * The default application entry page is the home page
702
710
  * @default 'pages/index' or 'pages/index/index'
@@ -751,7 +759,7 @@ interface Options {
751
759
  onAfterWriteFile: (ctx: PageContext) => void;
752
760
  }
753
761
  type UserOptions = Partial<Options>;
754
- interface ResolvedOptions extends Omit<Options, 'dir' | 'homePage'> {
762
+ interface ResolvedOptions extends Omit<Options, 'dir' | 'homePage' | 'configSource'> {
755
763
  /**
756
764
  * Resolves to the `root` value from Vite config.
757
765
  * @default config.root
@@ -765,6 +773,7 @@ interface ResolvedOptions extends Omit<Options, 'dir' | 'homePage'> {
765
773
  * Resolved entry page
766
774
  */
767
775
  homePage: string[];
776
+ configSource: LoadConfigSource<PagesConfig>[];
768
777
  }
769
778
  interface PagePath {
770
779
  relativePath: string;
@@ -816,4 +825,4 @@ declare function getRouteBlock(path: string, blockStr: SFCBlock | undefined, opt
816
825
 
817
826
  declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
818
827
 
819
- 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, SubPageMetaDatum, TabBar, TabBarItem, TheWindow, UniIdRouter, UserOptions, UserPagesConfig, VitePluginUniPages, checkPagesJsonFile, debug, debugType, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getPagesConfigSourcePaths, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isConfigFile, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, useCachedPages, writeFileSync };
828
+ 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 };
package/dist/index.mjs CHANGED
@@ -132,8 +132,8 @@ function mergePageMetaDataArray(pageMetaData) {
132
132
  }
133
133
  return result;
134
134
  }
135
- async function getPagesConfigSourcePaths() {
136
- return await fg("pages.config.(ts|mts|cts|js|cjs|mjs|json)", {
135
+ async function getPagesConfigSourcePaths(configSource) {
136
+ return await fg(configSource.map((v) => v.files).flat(), {
137
137
  deep: 0,
138
138
  onlyFiles: true,
139
139
  absolute: true
@@ -163,6 +163,7 @@ function useCachedPages() {
163
163
 
164
164
  function resolveOptions(userOptions, viteRoot) {
165
165
  const {
166
+ configSource = "pages.config.(ts|mts|cts|js|cjs|mjs|json)",
166
167
  homePage = ["pages/index", "pages/index/index"],
167
168
  mergePages = true,
168
169
  dir = "src/pages",
@@ -192,9 +193,11 @@ function resolveOptions(userOptions, viteRoot) {
192
193
  const root = viteRoot || slash(process$1.cwd());
193
194
  const resolvedDirs = resolvePageDirs(dir, root, exclude);
194
195
  const resolvedSubDirs = subPackages.map((dir2) => slash(dir2));
195
- const ResolvedHomePage = typeof homePage === "string" ? [homePage] : homePage;
196
+ const resolvedHomePage = typeof homePage === "string" ? [homePage] : homePage;
197
+ const resolvedConfigSource = typeof configSource === "string" ? [{ files: configSource }] : configSource;
196
198
  const resolvedOptions = {
197
- homePage: ResolvedHomePage,
199
+ configSource: Array.isArray(resolvedConfigSource) ? resolvedConfigSource : [resolvedConfigSource],
200
+ homePage: resolvedHomePage,
198
201
  mergePages,
199
202
  dirs: resolvedDirs,
200
203
  subPackages: resolvedSubDirs,
@@ -247,15 +250,27 @@ function writeFileSync(path, content) {
247
250
  fs.writeFileSync(path, content, { encoding: "utf-8" });
248
251
  }
249
252
 
253
+ var __defProp = Object.defineProperty;
254
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
255
+ var __publicField = (obj, key, value) => {
256
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
257
+ return value;
258
+ };
250
259
  let lsatPagesJson = "";
251
260
  const { setCache, hasChanged } = useCachedPages();
252
261
  class PageContext {
253
262
  constructor(userOptions, viteRoot = process$1.cwd()) {
254
- this.pagesPath = [];
255
- this.subPagesPath = {};
256
- this.pageMetaData = [];
257
- this.subPageMetaData = [];
258
- this.resolvedPagesJSONPath = "";
263
+ __publicField(this, "_server");
264
+ __publicField(this, "pagesGlobConfig");
265
+ __publicField(this, "pagesPath", []);
266
+ __publicField(this, "subPagesPath", {});
267
+ __publicField(this, "pageMetaData", []);
268
+ __publicField(this, "subPageMetaData", []);
269
+ __publicField(this, "resolvedPagesJSONPath", "");
270
+ __publicField(this, "rawOptions");
271
+ __publicField(this, "root");
272
+ __publicField(this, "options");
273
+ __publicField(this, "logger");
259
274
  this.rawOptions = userOptions;
260
275
  this.root = slash(viteRoot);
261
276
  debug.options("root", this.root);
@@ -273,11 +288,8 @@ class PageContext {
273
288
  this.logger = logger;
274
289
  }
275
290
  async loadUserPagesConfig() {
276
- const { config } = await loadConfig({ cwd: this.root, sources: [{ files: "pages.config" }] });
277
- if (!config) {
278
- this.logger?.warn("Can't found pages.config, please create pages.config.(ts|mts|cts|js|cjs|mjs|json)");
279
- process$1.exit(-1);
280
- }
291
+ const sources = this.options.configSource;
292
+ const { config } = await loadConfig({ cwd: this.root, sources, defaults: {} });
281
293
  this.pagesGlobConfig = config;
282
294
  debug.options(config);
283
295
  }
@@ -305,7 +317,7 @@ class PageContext {
305
317
  }
306
318
  async setupWatcher(watcher) {
307
319
  if (!isH5) {
308
- const configs = await getPagesConfigSourcePaths();
320
+ const configs = await getPagesConfigSourcePaths(this.options.configSource);
309
321
  watcher.add(configs);
310
322
  }
311
323
  const targetDirs = [...this.options.dirs, ...this.options.subPackages].map((v) => slash(path.resolve(this.root, v)));
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.6",
4
+ "version": "0.2.7",
5
5
  "description": "File system based routing for uni-app applications using Vite",
6
6
  "author": "KeJun",
7
7
  "license": "MIT",
@@ -15,16 +15,21 @@
15
15
  "sideEffects": false,
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/index.d.ts",
19
- "require": "./dist/index.cjs",
20
- "import": "./dist/index.mjs"
18
+ "require": {
19
+ "types": "./dist/index.d.cts",
20
+ "default": "./dist/index.cjs"
21
+ },
22
+ "import": {
23
+ "types": "./dist/index.d.mts",
24
+ "default": "./dist/index.mjs"
25
+ }
21
26
  },
22
27
  "./client": {
23
28
  "types": "./client.d.ts"
24
29
  }
25
30
  },
26
- "main": "./dist/index.mjs",
27
- "module": "./dist/index.cjs",
31
+ "main": "./dist/index.cjs",
32
+ "module": "./dist/index.mjs",
28
33
  "types": "./dist/index.d.ts",
29
34
  "files": [
30
35
  "dist",
@@ -38,14 +43,14 @@
38
43
  "fast-glob": "^3.3.1",
39
44
  "json5": "^2.2.3",
40
45
  "lodash-unified": "^1.0.3",
41
- "magic-string": "^0.30.2",
46
+ "magic-string": "^0.30.3",
42
47
  "unconfig": "^0.3.10",
43
48
  "yaml": "^2.3.1"
44
49
  },
45
50
  "devDependencies": {
46
- "@antfu/utils": "^0.7.5",
51
+ "@antfu/utils": "^0.7.6",
47
52
  "@types/debug": "^4.1.8",
48
- "@types/node": "^18.17.1"
53
+ "@types/node": "^18.17.9"
49
54
  },
50
55
  "scripts": {
51
56
  "build": "unbuild",