@uni-helper/vite-plugin-uni-pages 0.4.0 → 0.4.2
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/README.md +45 -3
- package/dist/index.cjs +12 -17
- package/dist/index.d.cts +46 -5
- package/dist/index.d.mts +48 -6
- package/dist/index.mjs +13 -6
- package/index.d.ts +2 -3
- package/package.json +8 -8
- package/dist/chunk-B4FMCO8f.mjs +0 -28
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ export default defineConfig({
|
|
|
33
33
|
import { defineUniPages } from '@uni-helper/vite-plugin-uni-pages'
|
|
34
34
|
|
|
35
35
|
export default defineUniPages({
|
|
36
|
-
// 你可以手动指定 pages
|
|
36
|
+
// 你可以手动指定 pages,与 definePage 合并时,pages.config.ts 中的同名属性会覆盖 definePage。
|
|
37
37
|
// 如果不手动指定 pages,插件会自动扫描页面并生成 pages.json。
|
|
38
38
|
// pages: [],
|
|
39
39
|
|
|
@@ -103,10 +103,15 @@ interface UserOptions {
|
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
105
|
* 分包页面目录的根目录列表
|
|
106
|
+
*
|
|
106
107
|
* 用于 uni-app 的分包加载功能
|
|
108
|
+
*
|
|
109
|
+
* 支持字符串格式(目录路径)或对象格式(自定义 pages.json 中的 root)
|
|
110
|
+
*
|
|
111
|
+
* 更多上下文参考 <https://github.com/uni-helper/vite-plugin-uni-pages/issues/271>
|
|
107
112
|
* @default []
|
|
108
113
|
*/
|
|
109
|
-
subPackages?: string[]
|
|
114
|
+
subPackages?: (string | { dir: string; root: string })[]
|
|
110
115
|
|
|
111
116
|
/**
|
|
112
117
|
* pages.json 所在目录
|
|
@@ -159,7 +164,10 @@ interface UserOptions {
|
|
|
159
164
|
|
|
160
165
|
- **加载用户配置**:通过 `unconfig` 加载 `pages.config.ts` 等配置文件,获取手动指定的页面元数据(`pages`、`subPackages`、`globalStyle` 等)
|
|
161
166
|
- **扫描页面文件**(仅在 `mergePages: true` 时):根据 `dir` 和 `subPackages` 扫描文件系统,为每个页面文件创建 `Page` 实例
|
|
162
|
-
-
|
|
167
|
+
- **合并页面元数据**:将扫描到的页面与用户配置中的页面元数据合并。优先级从低到高:
|
|
168
|
+
1. `globalStyle`(`pages.config.ts` 中的全局样式)
|
|
169
|
+
2. `definePage()`(`.vue` 文件中通过宏定义的页面配置)
|
|
170
|
+
3. `pages.config.ts` 中 `pages` 数组里对应 path 的条目(最高优先级,会覆盖 `definePage` 的同名属性)
|
|
163
171
|
- **生成并写入**:序列化为 `pages.json`,写入到 `outDir` 目录,并生成 TypeScript 类型声明
|
|
164
172
|
|
|
165
173
|
### 配置示例
|
|
@@ -204,6 +212,40 @@ export default defineConfig({
|
|
|
204
212
|
|
|
205
213
|
文件名内不能带有额外的 `.` 分隔符,如 `index.v1.vue` 不合法。这是小程序的限制,并非本插件的限制。
|
|
206
214
|
|
|
215
|
+
### 支持 monorepo 吗?
|
|
216
|
+
|
|
217
|
+
在 monorepo 项目中,如果页面分布在多个 package 中,可以使用 `subPackages` 配置的对象格式来自定义生成的 `root` 路径。
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
// vite.config.ts
|
|
221
|
+
import UniPages from '@uni-helper/vite-plugin-uni-pages'
|
|
222
|
+
import { defineConfig } from 'vite'
|
|
223
|
+
|
|
224
|
+
export default defineConfig({
|
|
225
|
+
plugins: [
|
|
226
|
+
UniPages({
|
|
227
|
+
subPackages: [
|
|
228
|
+
// 简写格式(原有功能)
|
|
229
|
+
'src/pages-sub',
|
|
230
|
+
// 对象格式(monorepo 支持)
|
|
231
|
+
{
|
|
232
|
+
dir: '../../packages/login/src/pages', // 页面目录路径
|
|
233
|
+
root: 'packages/login/src/pages', // 自定义 pages.json 中的 root
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
dir: '../../packages/user/src/pages',
|
|
237
|
+
root: 'packages/user/src/pages',
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
}),
|
|
241
|
+
],
|
|
242
|
+
})
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
这样生成的 `pages.json` 中 `subPackages.root` 将使用自定义的值,而不是基于文件系统计算的相对路径,避免出现 `..` 造成路径问题。
|
|
246
|
+
|
|
247
|
+
更多上下文参考 <https://github.com/uni-helper/vite-plugin-uni-pages/issues/271>。
|
|
248
|
+
|
|
207
249
|
## 感谢
|
|
208
250
|
|
|
209
251
|
- [hannoeru/vite-plugin-pages](https://github.com/hannoeru/vite-plugin-pages)
|
package/dist/index.cjs
CHANGED
|
@@ -63,7 +63,6 @@ typescript = __toESM(typescript, 1);
|
|
|
63
63
|
let _babel_types = require("@babel/types");
|
|
64
64
|
_babel_types = __toESM(_babel_types, 1);
|
|
65
65
|
let _vue_compiler_sfc = require("@vue/compiler-sfc");
|
|
66
|
-
let _uni_helper_uni_pages_types = require("@uni-helper/uni-pages-types");
|
|
67
66
|
//#region src/constant.ts
|
|
68
67
|
/** Virtual module identifier for Vite module resolution */
|
|
69
68
|
const MODULE_ID_VIRTUAL = "virtual:uni-pages";
|
|
@@ -428,7 +427,14 @@ function resolveOptions(userOptions, viteRoot = node_process.default.cwd()) {
|
|
|
428
427
|
], minify = false, debug = false, onBeforeLoadUserConfig = () => {}, onAfterLoadUserConfig = () => {}, onBeforeScanPages = () => {}, onAfterScanPages = () => {}, onBeforeMergePageMetaData = () => {}, onAfterMergePageMetaData = () => {}, onBeforeWriteFile = () => {}, onAfterWriteFile = () => {} } = userOptions;
|
|
429
428
|
const root = viteRoot || slash(node_process.default.env.VITE_ROOT_DIR || node_process.default.cwd());
|
|
430
429
|
const resolvedDirs = resolvePageDirs(dir, root, exclude);
|
|
431
|
-
const
|
|
430
|
+
const subPackageRootMap = /* @__PURE__ */ new Map();
|
|
431
|
+
const resolvedSubDirs = [];
|
|
432
|
+
for (const sub of subPackages) if (typeof sub === "string") resolvedSubDirs.push(slash(sub));
|
|
433
|
+
else {
|
|
434
|
+
const dirPath = slash(sub.dir);
|
|
435
|
+
resolvedSubDirs.push(dirPath);
|
|
436
|
+
subPackageRootMap.set(dirPath, sub.root);
|
|
437
|
+
}
|
|
432
438
|
const resolvedHomePage = typeof homePage === "string" ? [homePage] : homePage;
|
|
433
439
|
const resolvedConfigSource = typeof configSource === "string" ? [{ files: configSource }] : configSource;
|
|
434
440
|
return {
|
|
@@ -438,6 +444,7 @@ function resolveOptions(userOptions, viteRoot = node_process.default.cwd()) {
|
|
|
438
444
|
mergePages,
|
|
439
445
|
dirs: resolvedDirs,
|
|
440
446
|
subPackages: resolvedSubDirs,
|
|
447
|
+
subPackageRootMap,
|
|
441
448
|
outDir,
|
|
442
449
|
exclude,
|
|
443
450
|
root,
|
|
@@ -897,7 +904,7 @@ var PageContext = class {
|
|
|
897
904
|
const subPackages = this.pagesGlobConfig?.subPackages || [];
|
|
898
905
|
for (const [dir, pages] of this.subPages) {
|
|
899
906
|
const basePath = slash(node_path.default.join(this.options.root, this.options.outDir));
|
|
900
|
-
const root = slash(node_path.default.relative(basePath, node_path.default.join(this.options.root, dir)));
|
|
907
|
+
const root = this.options.subPackageRootMap.get(dir) ?? slash(node_path.default.relative(basePath, node_path.default.join(this.options.root, dir)));
|
|
901
908
|
const globPackage = subPackages?.find((v) => v.root === root);
|
|
902
909
|
subPageMaps[root] = await this.parsePages(pages, "sub", globPackage?.pages);
|
|
903
910
|
subPageMaps[root] = subPageMaps[root].map((page) => ({
|
|
@@ -1257,6 +1264,8 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
|
|
|
1257
1264
|
function defineUniPages(config) {
|
|
1258
1265
|
return config;
|
|
1259
1266
|
}
|
|
1267
|
+
//#endregion
|
|
1268
|
+
//#region src/index.ts
|
|
1260
1269
|
/**
|
|
1261
1270
|
* vite-plugin-uni-pages plugin main entry
|
|
1262
1271
|
*
|
|
@@ -1346,12 +1355,6 @@ exports.default = VitePluginUniPages;
|
|
|
1346
1355
|
exports.babelGenerate = babelGenerate;
|
|
1347
1356
|
exports.checkPagesJsonFileSync = checkPagesJsonFileSync;
|
|
1348
1357
|
exports.debug = debug$1;
|
|
1349
|
-
Object.defineProperty(exports, "definePage", {
|
|
1350
|
-
enumerable: true,
|
|
1351
|
-
get: function() {
|
|
1352
|
-
return _uni_helper_uni_pages_types.definePage;
|
|
1353
|
-
}
|
|
1354
|
-
});
|
|
1355
1358
|
exports.defineUniPages = defineUniPages;
|
|
1356
1359
|
exports.extsToGlob = extsToGlob;
|
|
1357
1360
|
exports.findImports = findImports;
|
|
@@ -1368,11 +1371,3 @@ exports.sleep = sleep;
|
|
|
1368
1371
|
exports.stripType = stripType;
|
|
1369
1372
|
exports.tryPageMetaFromMacro = tryPageMetaFromMacro;
|
|
1370
1373
|
exports.writeFileWithLock = writeFileWithLock;
|
|
1371
|
-
Object.keys(_uni_helper_uni_pages_types).forEach(function(k) {
|
|
1372
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
1373
|
-
enumerable: true,
|
|
1374
|
-
get: function() {
|
|
1375
|
-
return _uni_helper_uni_pages_types[k];
|
|
1376
|
-
}
|
|
1377
|
-
});
|
|
1378
|
-
});
|
package/dist/index.d.cts
CHANGED
|
@@ -378,10 +378,18 @@ interface Options {
|
|
|
378
378
|
*/
|
|
379
379
|
dir: string;
|
|
380
380
|
/**
|
|
381
|
-
*
|
|
381
|
+
* Sub-package page directories for uni-app sub-package loading
|
|
382
|
+
*
|
|
383
|
+
* Supports string format (directory path) or object format (custom root in pages.json)
|
|
384
|
+
*
|
|
385
|
+
* In monorepo projects, pages may be located outside the project root.
|
|
386
|
+
* Use object format to specify a custom root that appears in pages.json,
|
|
387
|
+
* avoiding '..' in the generated root path.
|
|
388
|
+
*
|
|
389
|
+
* @see https://github.com/uni-helper/vite-plugin-uni-pages/issues/271
|
|
382
390
|
* @default []
|
|
383
391
|
*/
|
|
384
|
-
subPackages: string[];
|
|
392
|
+
subPackages: (string | SubPackageConfig)[];
|
|
385
393
|
/**
|
|
386
394
|
* pages.json dir
|
|
387
395
|
* @default "src"
|
|
@@ -416,7 +424,7 @@ type UserOptions = Partial<Options>;
|
|
|
416
424
|
* Resolved configuration options interface
|
|
417
425
|
* Configuration processed by resolveOptions, all paths resolved to absolute paths
|
|
418
426
|
*/
|
|
419
|
-
interface ResolvedOptions extends Omit<Options, 'dir' | 'homePage' | 'configSource' | 'dts'> {
|
|
427
|
+
interface ResolvedOptions extends Omit<Options, 'dir' | 'homePage' | 'configSource' | 'dts' | 'subPackages'> {
|
|
420
428
|
/**
|
|
421
429
|
* Resolves to the `root` value from Vite config.
|
|
422
430
|
* @default config.root
|
|
@@ -432,6 +440,39 @@ interface ResolvedOptions extends Omit<Options, 'dir' | 'homePage' | 'configSour
|
|
|
432
440
|
*/
|
|
433
441
|
homePage: string[];
|
|
434
442
|
configSource: LoadConfigSource<index_d_exports$1.PagesConfig>[];
|
|
443
|
+
/**
|
|
444
|
+
* Resolved sub-package directories
|
|
445
|
+
*/
|
|
446
|
+
subPackages: string[];
|
|
447
|
+
/**
|
|
448
|
+
* Custom root mapping for sub-packages (dir -> root)
|
|
449
|
+
* Used for monorepo support to specify custom root paths in pages.json
|
|
450
|
+
*/
|
|
451
|
+
subPackageRootMap: Map<string, string>;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Sub-package configuration interface
|
|
455
|
+
* Allows customizing the root path in pages.json for monorepo support
|
|
456
|
+
*
|
|
457
|
+
* In monorepo projects, pages may be located outside the project root (e.g., ../../packages/login/src/pages).
|
|
458
|
+
* By default, the plugin generates root paths with '..', which uni-app does not support.
|
|
459
|
+
* Use this config to specify a custom root that appears in pages.json instead.
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* ```ts
|
|
463
|
+
* subPackages: [
|
|
464
|
+
* {
|
|
465
|
+
* dir: '../../packages/login/src/pages', // Physical directory to scan
|
|
466
|
+
* root: 'packages/login/src/pages', // Custom root in pages.json
|
|
467
|
+
* }
|
|
468
|
+
* ]
|
|
469
|
+
* ```
|
|
470
|
+
*/
|
|
471
|
+
interface SubPackageConfig {
|
|
472
|
+
/** Physical directory path to scan for page files */
|
|
473
|
+
dir: string;
|
|
474
|
+
/** Custom root path that appears in pages.json subPackages.root */
|
|
475
|
+
root: string;
|
|
435
476
|
}
|
|
436
477
|
/**
|
|
437
478
|
* Page path information interface
|
|
@@ -491,7 +532,7 @@ declare function resolveOptions(userOptions: UserOptions, viteRoot?: string): Re
|
|
|
491
532
|
*/
|
|
492
533
|
declare function resolvePageDirs(dir: string, root: string, exclude: string[]): string[];
|
|
493
534
|
declare namespace index_d_exports {
|
|
494
|
-
export { ConfigSource, DefinePage, ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, MaybeCallable, MaybePromise, MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPageMetaDatum, UserOptions, UserPageMeta, UserTabBarItem, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, debugType, VitePluginUniPages as default, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep, stripType, tryPageMetaFromMacro, writeFileWithLock };
|
|
535
|
+
export { ConfigSource, DefinePage, ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, MaybeCallable, MaybePromise, MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPackageConfig, SubPageMetaDatum, UserOptions, UserPageMeta, UserTabBarItem, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, debugType, VitePluginUniPages as default, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep, stripType, tryPageMetaFromMacro, writeFileWithLock };
|
|
495
536
|
}
|
|
496
537
|
/**
|
|
497
538
|
* vite-plugin-uni-pages plugin main entry
|
|
@@ -507,4 +548,4 @@ declare namespace index_d_exports {
|
|
|
507
548
|
*/
|
|
508
549
|
declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
|
|
509
550
|
//#endregion
|
|
510
|
-
export { ConfigSource, type DefinePage, type ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, type MaybeCallable, type MaybePromise, type MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, type PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, type SubPageMetaDatum, UserOptions, type UserPageMeta, type UserTabBarItem, VitePluginUniPages, VitePluginUniPages as default, babelGenerate, checkPagesJsonFileSync, debug, debugType, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep, stripType, tryPageMetaFromMacro, writeFileWithLock };
|
|
551
|
+
export { ConfigSource, type DefinePage, type ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, type MaybeCallable, type MaybePromise, type MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, type PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPackageConfig, type SubPageMetaDatum, UserOptions, type UserPageMeta, type UserTabBarItem, VitePluginUniPages, VitePluginUniPages as default, babelGenerate, checkPagesJsonFileSync, debug, debugType, type definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep, stripType, tryPageMetaFromMacro, writeFileWithLock };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
1
2
|
import { FSWatcher } from "chokidar";
|
|
2
3
|
import { Logger, Plugin, ViteDevServer } from "vite";
|
|
3
4
|
import fs from "node:fs";
|
|
@@ -9,7 +10,7 @@ import { SFCDescriptor, SFCParseOptions } from "@vue/compiler-sfc";
|
|
|
9
10
|
import { DefinePage, ExcludeIndexSignature, MaybeCallable, MaybePromise, MaybePromiseCallable, PageMetaDatum, SubPageMetaDatum, UserPageMeta, UserPagesConfig, UserTabBarItem, definePage } from "@uni-helper/uni-pages-types";
|
|
10
11
|
export * from "@uni-helper/uni-pages-types";
|
|
11
12
|
|
|
12
|
-
//#region
|
|
13
|
+
//#region \0rolldown/runtime.js
|
|
13
14
|
declare namespace index_d_exports$1 {
|
|
14
15
|
export { defineUniPages };
|
|
15
16
|
}
|
|
@@ -378,10 +379,18 @@ interface Options {
|
|
|
378
379
|
*/
|
|
379
380
|
dir: string;
|
|
380
381
|
/**
|
|
381
|
-
*
|
|
382
|
+
* Sub-package page directories for uni-app sub-package loading
|
|
383
|
+
*
|
|
384
|
+
* Supports string format (directory path) or object format (custom root in pages.json)
|
|
385
|
+
*
|
|
386
|
+
* In monorepo projects, pages may be located outside the project root.
|
|
387
|
+
* Use object format to specify a custom root that appears in pages.json,
|
|
388
|
+
* avoiding '..' in the generated root path.
|
|
389
|
+
*
|
|
390
|
+
* @see https://github.com/uni-helper/vite-plugin-uni-pages/issues/271
|
|
382
391
|
* @default []
|
|
383
392
|
*/
|
|
384
|
-
subPackages: string[];
|
|
393
|
+
subPackages: (string | SubPackageConfig)[];
|
|
385
394
|
/**
|
|
386
395
|
* pages.json dir
|
|
387
396
|
* @default "src"
|
|
@@ -416,7 +425,7 @@ type UserOptions = Partial<Options>;
|
|
|
416
425
|
* Resolved configuration options interface
|
|
417
426
|
* Configuration processed by resolveOptions, all paths resolved to absolute paths
|
|
418
427
|
*/
|
|
419
|
-
interface ResolvedOptions extends Omit<Options, 'dir' | 'homePage' | 'configSource' | 'dts'> {
|
|
428
|
+
interface ResolvedOptions extends Omit<Options, 'dir' | 'homePage' | 'configSource' | 'dts' | 'subPackages'> {
|
|
420
429
|
/**
|
|
421
430
|
* Resolves to the `root` value from Vite config.
|
|
422
431
|
* @default config.root
|
|
@@ -432,6 +441,39 @@ interface ResolvedOptions extends Omit<Options, 'dir' | 'homePage' | 'configSour
|
|
|
432
441
|
*/
|
|
433
442
|
homePage: string[];
|
|
434
443
|
configSource: LoadConfigSource<index_d_exports$1.PagesConfig>[];
|
|
444
|
+
/**
|
|
445
|
+
* Resolved sub-package directories
|
|
446
|
+
*/
|
|
447
|
+
subPackages: string[];
|
|
448
|
+
/**
|
|
449
|
+
* Custom root mapping for sub-packages (dir -> root)
|
|
450
|
+
* Used for monorepo support to specify custom root paths in pages.json
|
|
451
|
+
*/
|
|
452
|
+
subPackageRootMap: Map<string, string>;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Sub-package configuration interface
|
|
456
|
+
* Allows customizing the root path in pages.json for monorepo support
|
|
457
|
+
*
|
|
458
|
+
* In monorepo projects, pages may be located outside the project root (e.g., ../../packages/login/src/pages).
|
|
459
|
+
* By default, the plugin generates root paths with '..', which uni-app does not support.
|
|
460
|
+
* Use this config to specify a custom root that appears in pages.json instead.
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* ```ts
|
|
464
|
+
* subPackages: [
|
|
465
|
+
* {
|
|
466
|
+
* dir: '../../packages/login/src/pages', // Physical directory to scan
|
|
467
|
+
* root: 'packages/login/src/pages', // Custom root in pages.json
|
|
468
|
+
* }
|
|
469
|
+
* ]
|
|
470
|
+
* ```
|
|
471
|
+
*/
|
|
472
|
+
interface SubPackageConfig {
|
|
473
|
+
/** Physical directory path to scan for page files */
|
|
474
|
+
dir: string;
|
|
475
|
+
/** Custom root path that appears in pages.json subPackages.root */
|
|
476
|
+
root: string;
|
|
435
477
|
}
|
|
436
478
|
/**
|
|
437
479
|
* Page path information interface
|
|
@@ -491,7 +533,7 @@ declare function resolveOptions(userOptions: UserOptions, viteRoot?: string): Re
|
|
|
491
533
|
*/
|
|
492
534
|
declare function resolvePageDirs(dir: string, root: string, exclude: string[]): string[];
|
|
493
535
|
declare namespace index_d_exports {
|
|
494
|
-
export { ConfigSource, DefinePage, ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, MaybeCallable, MaybePromise, MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPageMetaDatum, UserOptions, UserPageMeta, UserTabBarItem, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, debugType, VitePluginUniPages as default, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep, stripType, tryPageMetaFromMacro, writeFileWithLock };
|
|
536
|
+
export { ConfigSource, DefinePage, ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, MaybeCallable, MaybePromise, MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPackageConfig, SubPageMetaDatum, UserOptions, UserPageMeta, UserTabBarItem, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, debugType, VitePluginUniPages as default, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep, stripType, tryPageMetaFromMacro, writeFileWithLock };
|
|
495
537
|
}
|
|
496
538
|
/**
|
|
497
539
|
* vite-plugin-uni-pages plugin main entry
|
|
@@ -507,4 +549,4 @@ declare namespace index_d_exports {
|
|
|
507
549
|
*/
|
|
508
550
|
declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
|
|
509
551
|
//#endregion
|
|
510
|
-
export { ConfigSource, type DefinePage, type ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, type MaybeCallable, type MaybePromise, type MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, type PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, type SubPageMetaDatum, UserOptions, type UserPageMeta, type UserTabBarItem, VitePluginUniPages, VitePluginUniPages as default, babelGenerate, checkPagesJsonFileSync, debug, debugType, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep, stripType, tryPageMetaFromMacro, writeFileWithLock };
|
|
552
|
+
export { ConfigSource, type DefinePage, type ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, type MaybeCallable, type MaybePromise, type MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, type PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPackageConfig, type SubPageMetaDatum, UserOptions, type UserPageMeta, type UserTabBarItem, VitePluginUniPages, VitePluginUniPages as default, babelGenerate, checkPagesJsonFileSync, debug, debugType, type definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep, stripType, tryPageMetaFromMacro, writeFileWithLock };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "./chunk-B4FMCO8f.mjs";
|
|
2
1
|
import { createRequire } from "node:module";
|
|
3
2
|
import path, { dirname, extname, join, resolve } from "node:path";
|
|
4
3
|
import process from "node:process";
|
|
@@ -23,8 +22,6 @@ import groupBy from "lodash.groupby";
|
|
|
23
22
|
import * as ts from "typescript";
|
|
24
23
|
import * as t from "@babel/types";
|
|
25
24
|
import { parse as parse$1 } from "@vue/compiler-sfc";
|
|
26
|
-
import { definePage } from "@uni-helper/uni-pages-types";
|
|
27
|
-
export * from "@uni-helper/uni-pages-types";
|
|
28
25
|
//#region src/constant.ts
|
|
29
26
|
/** Virtual module identifier for Vite module resolution */
|
|
30
27
|
const MODULE_ID_VIRTUAL = "virtual:uni-pages";
|
|
@@ -389,7 +386,14 @@ function resolveOptions(userOptions, viteRoot = process.cwd()) {
|
|
|
389
386
|
], minify = false, debug = false, onBeforeLoadUserConfig = () => {}, onAfterLoadUserConfig = () => {}, onBeforeScanPages = () => {}, onAfterScanPages = () => {}, onBeforeMergePageMetaData = () => {}, onAfterMergePageMetaData = () => {}, onBeforeWriteFile = () => {}, onAfterWriteFile = () => {} } = userOptions;
|
|
390
387
|
const root = viteRoot || slash(process.env.VITE_ROOT_DIR || process.cwd());
|
|
391
388
|
const resolvedDirs = resolvePageDirs(dir, root, exclude);
|
|
392
|
-
const
|
|
389
|
+
const subPackageRootMap = /* @__PURE__ */ new Map();
|
|
390
|
+
const resolvedSubDirs = [];
|
|
391
|
+
for (const sub of subPackages) if (typeof sub === "string") resolvedSubDirs.push(slash(sub));
|
|
392
|
+
else {
|
|
393
|
+
const dirPath = slash(sub.dir);
|
|
394
|
+
resolvedSubDirs.push(dirPath);
|
|
395
|
+
subPackageRootMap.set(dirPath, sub.root);
|
|
396
|
+
}
|
|
393
397
|
const resolvedHomePage = typeof homePage === "string" ? [homePage] : homePage;
|
|
394
398
|
const resolvedConfigSource = typeof configSource === "string" ? [{ files: configSource }] : configSource;
|
|
395
399
|
return {
|
|
@@ -399,6 +403,7 @@ function resolveOptions(userOptions, viteRoot = process.cwd()) {
|
|
|
399
403
|
mergePages,
|
|
400
404
|
dirs: resolvedDirs,
|
|
401
405
|
subPackages: resolvedSubDirs,
|
|
406
|
+
subPackageRootMap,
|
|
402
407
|
outDir,
|
|
403
408
|
exclude,
|
|
404
409
|
root,
|
|
@@ -858,7 +863,7 @@ var PageContext = class {
|
|
|
858
863
|
const subPackages = this.pagesGlobConfig?.subPackages || [];
|
|
859
864
|
for (const [dir, pages] of this.subPages) {
|
|
860
865
|
const basePath = slash(path.join(this.options.root, this.options.outDir));
|
|
861
|
-
const root = slash(path.relative(basePath, path.join(this.options.root, dir)));
|
|
866
|
+
const root = this.options.subPackageRootMap.get(dir) ?? slash(path.relative(basePath, path.join(this.options.root, dir)));
|
|
862
867
|
const globPackage = subPackages?.find((v) => v.root === root);
|
|
863
868
|
subPageMaps[root] = await this.parsePages(pages, "sub", globPackage?.pages);
|
|
864
869
|
subPageMaps[root] = subPageMaps[root].map((page) => ({
|
|
@@ -1218,6 +1223,8 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
|
|
|
1218
1223
|
function defineUniPages(config) {
|
|
1219
1224
|
return config;
|
|
1220
1225
|
}
|
|
1226
|
+
//#endregion
|
|
1227
|
+
//#region src/index.ts
|
|
1221
1228
|
/**
|
|
1222
1229
|
* vite-plugin-uni-pages plugin main entry
|
|
1223
1230
|
*
|
|
@@ -1296,4 +1303,4 @@ function VitePluginUniPages(userOptions = {}) {
|
|
|
1296
1303
|
};
|
|
1297
1304
|
}
|
|
1298
1305
|
//#endregion
|
|
1299
|
-
export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, VitePluginUniPages as default, babelGenerate, checkPagesJsonFileSync, debug,
|
|
1306
|
+
export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, VitePluginUniPages as default, babelGenerate, checkPagesJsonFileSync, debug, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep, stripType, tryPageMetaFromMacro, writeFileWithLock };
|
package/index.d.ts
CHANGED
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.4.
|
|
4
|
+
"version": "0.4.2",
|
|
5
5
|
"description": "File system based routing for uni-app applications using Vite",
|
|
6
6
|
"author": "KeJun",
|
|
7
7
|
"maintainers": [
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
29
|
"import": {
|
|
30
|
-
"types": "./index.d.
|
|
30
|
+
"types": "./dist/index.d.mts",
|
|
31
31
|
"default": "./dist/index.mjs"
|
|
32
32
|
},
|
|
33
33
|
"require": {
|
|
34
|
-
"types": "./index.d.
|
|
34
|
+
"types": "./dist/index.d.cts",
|
|
35
35
|
"default": "./dist/index.cjs"
|
|
36
36
|
}
|
|
37
37
|
},
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"vite": "^5.0.0"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@babel/generator": "^7.29.
|
|
56
|
-
"@babel/types": "^7.29.
|
|
55
|
+
"@babel/generator": "^7.29.7",
|
|
56
|
+
"@babel/types": "^7.29.7",
|
|
57
57
|
"@types/proper-lockfile": "^4.1.4",
|
|
58
58
|
"@uni-helper/uni-env": "^0.2.2",
|
|
59
59
|
"@vue/compiler-sfc": "~3.4.38",
|
|
@@ -67,19 +67,19 @@
|
|
|
67
67
|
"lodash.groupby": "^4.6.0",
|
|
68
68
|
"magic-string": "^0.30.21",
|
|
69
69
|
"proper-lockfile": "^4.1.2",
|
|
70
|
-
"tinyglobby": "^0.2.
|
|
70
|
+
"tinyglobby": "^0.2.17",
|
|
71
71
|
"typescript": "^6.0.3",
|
|
72
72
|
"unconfig": "^7.5.0",
|
|
73
73
|
"write-file-atomic": "^7.0.1",
|
|
74
74
|
"yaml": "^2.9.0",
|
|
75
|
-
"@uni-helper/uni-pages-types": "0.4.
|
|
75
|
+
"@uni-helper/uni-pages-types": "0.4.2"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@antfu/utils": "^9.3.0",
|
|
79
79
|
"@types/babel__generator": "^7.27.0",
|
|
80
80
|
"@types/debug": "^4.1.13",
|
|
81
81
|
"@types/lodash.groupby": "^4.6.9",
|
|
82
|
-
"@types/node": "^24.
|
|
82
|
+
"@types/node": "^24.13.2",
|
|
83
83
|
"@types/write-file-atomic": "^4.0.3",
|
|
84
84
|
"vite": "^5.4.21"
|
|
85
85
|
},
|
package/dist/chunk-B4FMCO8f.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
//#region \0rolldown/runtime.js
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __exportAll = (all, no_symbols) => {
|
|
8
|
-
let target = {};
|
|
9
|
-
for (var name in all) __defProp(target, name, {
|
|
10
|
-
get: all[name],
|
|
11
|
-
enumerable: true
|
|
12
|
-
});
|
|
13
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
14
|
-
return target;
|
|
15
|
-
};
|
|
16
|
-
var __copyProps = (to, from, except, desc) => {
|
|
17
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
18
|
-
key = keys[i];
|
|
19
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
20
|
-
get: ((k) => from[k]).bind(null, key),
|
|
21
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
return to;
|
|
25
|
-
};
|
|
26
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
27
|
-
//#endregion
|
|
28
|
-
export { __reExport as n, __exportAll as t };
|