weapp-vite 6.7.7 → 6.9.0

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.
Files changed (55) hide show
  1. package/dist/auto-import-components/resolvers.d.mts +2 -0
  2. package/dist/auto-import-components/resolvers.mjs +309 -350
  3. package/dist/auto-routes.d.mts +17 -0
  4. package/dist/auto-routes.mjs +48 -78
  5. package/dist/cli.d.mts +1 -0
  6. package/dist/cli.mjs +2171 -2398
  7. package/dist/config-IEj3IfSy.d.mts +3128 -0
  8. package/dist/config.d.mts +2 -0
  9. package/dist/config.mjs +8 -31
  10. package/dist/createContext-CDgRHY26.mjs +19 -0
  11. package/dist/file-UprqcX9e.mjs +356 -0
  12. package/dist/getInstance-jl4yXdc0.mjs +31841 -0
  13. package/dist/index-B5wBsuYI.d.mts +56 -0
  14. package/dist/index.d.mts +13 -0
  15. package/dist/index.mjs +9 -51
  16. package/dist/json.d.mts +2 -0
  17. package/dist/json.mjs +32 -14
  18. package/dist/logger-gutcwWKE.mjs +2 -0
  19. package/dist/mcp-pzGAH7ob.mjs +6415 -0
  20. package/dist/mcp.d.mts +30 -0
  21. package/dist/mcp.mjs +3 -18
  22. package/dist/pluginHost-SJdl15d3.mjs +24 -0
  23. package/dist/routes-o20IHwXa.d.mts +13 -0
  24. package/dist/{runtime.d.ts → runtime.d.mts} +12 -11
  25. package/dist/runtime.mjs +32 -11
  26. package/dist/types.d.mts +4 -0
  27. package/dist/types.mjs +1 -25
  28. package/dist/volar.d.mts +2 -0
  29. package/dist/volar.mjs +3 -9
  30. package/package.json +29 -34
  31. package/dist/auto-import-components/resolvers.d.ts +0 -10
  32. package/dist/auto-routes.d.ts +0 -16
  33. package/dist/chunk-6YAZCQOZ.mjs +0 -9911
  34. package/dist/chunk-BGBLJUWD.mjs +0 -41
  35. package/dist/chunk-CWD4PR26.mjs +0 -39065
  36. package/dist/chunk-KTCETRUS.mjs +0 -426
  37. package/dist/chunk-KV5GZOAZ.mjs +0 -29
  38. package/dist/chunk-O2IN5LBB.mjs +0 -6
  39. package/dist/chunk-QD76G22N.mjs +0 -48
  40. package/dist/chunk-TXDI3ZWL.mjs +0 -33
  41. package/dist/chunk-W3UG2WZQ.mjs +0 -34
  42. package/dist/chunk-XIEFUUA5.mjs +0 -14
  43. package/dist/chunk-XQYQD5CM.mjs +0 -13
  44. package/dist/cli.d.ts +0 -2
  45. package/dist/config-CBlfQKJ-.d.ts +0 -1488
  46. package/dist/config.d.ts +0 -18
  47. package/dist/file-7NLX4QGQ.mjs +0 -29
  48. package/dist/getInstance-EKVIAYM4.mjs +0 -18
  49. package/dist/index.d.ts +0 -29
  50. package/dist/json.d.ts +0 -18
  51. package/dist/mcp.d.ts +0 -47
  52. package/dist/routes-74eLuiqj.d.ts +0 -12
  53. package/dist/types-B6irZnLM.d.ts +0 -46
  54. package/dist/types.d.ts +0 -29
  55. package/dist/volar.d.ts +0 -2
@@ -1,1488 +0,0 @@
1
- import { InlineConfig, UserConfig as UserConfig$2, ViteDevServer, build, ConfigEnv } from 'vite';
2
- import { GenerateType, Component, Theme, Sitemap, App, Page, Plugin } from '@weapp-core/schematics';
3
- import { WeappWebPluginOptions } from '@weapp-vite/web';
4
- import { InputOption, RolldownOutput, RolldownWatcher } from 'rolldown';
5
- import { Options } from 'rolldown-plugin-dts';
6
- import { CompilerOptions } from 'typescript';
7
- import { WrapPluginOptions } from 'vite-plugin-performance';
8
- import { PluginOptions } from 'vite-tsconfig-paths';
9
- import { WevuDefaults } from 'wevu';
10
- import { R as Resolver, a as ResolvedValue } from './types-B6irZnLM.js';
11
- import { LoggerConfig } from '@weapp-core/logger';
12
- import PQueue from 'p-queue';
13
- import { DetectResult } from 'package-manager-detector';
14
- import { PackageJson } from 'pkg-types';
15
- import { Buffer } from 'node:buffer';
16
- import { LRUCache } from 'lru-cache';
17
- import { A as AutoRoutes } from './routes-74eLuiqj.js';
18
-
19
- declare const WEAPP_VITE_HOST_NAME = "weapp-vite";
20
- type WeappViteRuntime = 'miniprogram' | 'web';
21
- interface WeappViteHostMeta {
22
- name: typeof WEAPP_VITE_HOST_NAME;
23
- runtime: WeappViteRuntime;
24
- }
25
- declare function createWeappViteHostMeta(runtime: WeappViteRuntime): WeappViteHostMeta;
26
- declare function applyWeappViteHostMeta(config: InlineConfig, runtime: WeappViteRuntime): InlineConfig;
27
- declare function resolveWeappViteHostMeta(config: Pick<InlineConfig, 'weappVite'> | undefined): WeappViteHostMeta | undefined;
28
- declare function isWeappViteHost(config: Pick<InlineConfig, 'weappVite'> | undefined): boolean;
29
- declare module 'vite' {
30
- interface UserConfig {
31
- weappVite?: WeappViteHostMeta;
32
- }
33
- interface ResolvedConfig {
34
- weappVite?: WeappViteHostMeta;
35
- }
36
- }
37
-
38
- type NpmBuildOptions = InlineConfig;
39
- type AlipayNpmMode = 'miniprogram_npm' | 'node_modules';
40
- interface Alias {
41
- find: string | RegExp;
42
- replacement: string;
43
- }
44
- interface ResolvedAlias {
45
- find: string | RegExp;
46
- replacement: string;
47
- }
48
- interface AliasOptions {
49
- /**
50
- * @example
51
- * ```ts
52
- * entries: [
53
- * {
54
- * find: '@',
55
- * replacement: path.resolve(import.meta.dirname, 'components'),
56
- * },
57
- * ]
58
- * ```
59
- * 这样你就可以在 json 里面使用:
60
- * ```json
61
- * {
62
- * "usingComponents": {
63
- * "navigation-bar": "@/navigation-bar/navigation-bar",
64
- * "ice-avatar": "@/avatar/avatar"
65
- * }
66
- * }
67
- * ```
68
- * 详见[json别名](/guide/alias.html#json-别名)文档
69
- */
70
- entries?: readonly Alias[] | {
71
- [find: string]: string;
72
- };
73
- }
74
- type MpPlatform = 'weapp' | 'alipay' | 'tt' | 'swan' | 'jd' | 'xhs';
75
- interface SubPackage {
76
- pages: string[];
77
- root: string;
78
- independent?: boolean;
79
- entry?: string;
80
- name?: string;
81
- dependencies?: (string | RegExp)[];
82
- inlineConfig?: Partial<InlineConfig>;
83
- }
84
- type SubPackageStyleScope = 'all' | 'pages' | 'components';
85
- interface SubPackageStyleConfigObject {
86
- /** 样式文件路径,可以是相对分包 root、相对 `srcRoot` 或绝对路径 */
87
- source: string;
88
- /**
89
- * 作用范围快捷配置:
90
- *
91
- * - `all`: 默认值,分包内所有页面与组件都会引入
92
- * - `pages`: 仅匹配分包 `pages/**`
93
- * - `components`: 仅匹配分包 `components/**`
94
- *
95
- * 可结合 `include` / `exclude` 进一步细分范围
96
- */
97
- scope?: SubPackageStyleScope;
98
- /** 自定义包含路径,支持传入单个 glob 或数组,默认覆盖分包内所有文件 */
99
- include?: string | string[];
100
- /** 自定义排除路径,支持传入单个 glob 或数组 */
101
- exclude?: string | string[];
102
- }
103
- type SubPackageStyleConfigEntry = string | SubPackageStyleConfigObject;
104
- interface SubPackageStyleEntry {
105
- /**
106
- * 源配置字符串(便于诊断)
107
- */
108
- source: string;
109
- /**
110
- * 原始样式文件的绝对路径
111
- */
112
- absolutePath: string;
113
- /**
114
- * 相对于 `srcRoot` 的输出路径(已转换为目标平台样式后缀)
115
- */
116
- outputRelativePath: string;
117
- /**
118
- * 源文件扩展名(包含 `.`)
119
- */
120
- inputExtension: string;
121
- /**
122
- * 作用域快捷字段,便于诊断输出
123
- */
124
- scope: SubPackageStyleScope;
125
- /**
126
- * 允许生效的 glob 列表(基于分包 root 的相对路径)
127
- */
128
- include: string[];
129
- /**
130
- * 排除的 glob 列表(基于分包 root 的相对路径)
131
- */
132
- exclude: string[];
133
- }
134
- type GenerateExtensionsOptions = Partial<{
135
- js: 'js' | 'ts' | (string & {});
136
- json: 'js' | 'ts' | 'json' | (string & {});
137
- wxml: 'wxml' | (string & {});
138
- wxss: 'wxss' | 'scss' | 'less' | 'css' | (string & {});
139
- }>;
140
- type GenerateDirsOptions = Partial<{
141
- app: string;
142
- page: string;
143
- component: string;
144
- }>;
145
- type GenerateFilenamesOptions = Partial<{
146
- app: string;
147
- page: string;
148
- component: string;
149
- }>;
150
- type GenerateFileType = 'js' | 'json' | 'wxml' | 'wxss';
151
- interface GenerateTemplateContext {
152
- type: GenerateType;
153
- fileType: GenerateFileType;
154
- fileName: string;
155
- outDir: string;
156
- extension: string;
157
- cwd: string;
158
- defaultCode?: string;
159
- }
160
- interface GenerateTemplateFileSource {
161
- path: string;
162
- }
163
- interface GenerateTemplateInlineSource {
164
- content: string;
165
- }
166
- type GenerateTemplateFactory = (context: GenerateTemplateContext) => string | Promise<string> | undefined;
167
- type GenerateTemplate = string | GenerateTemplateFileSource | GenerateTemplateInlineSource | GenerateTemplateFactory;
168
- type GenerateTemplateEntry = Partial<Record<GenerateFileType, GenerateTemplate>>;
169
- type GenerateTemplateScope = GenerateType | 'shared';
170
- type GenerateTemplatesConfig = Partial<Record<GenerateTemplateScope, GenerateTemplateEntry>>;
171
- interface GenerateOptions {
172
- /**
173
- * 生成文件的扩展名
174
- */
175
- extensions?: GenerateExtensionsOptions;
176
- /**
177
- * 默认生成文件的相对路径
178
- */
179
- dirs?: GenerateDirsOptions;
180
- /**
181
- * 默认生成文件的名称
182
- */
183
- filenames?: GenerateFilenamesOptions;
184
- /**
185
- * 自定义模板
186
- */
187
- templates?: GenerateTemplatesConfig;
188
- }
189
- interface CopyOptions {
190
- include?: CopyGlobs;
191
- exclude?: CopyGlobs;
192
- filter?: (filePath: string, index: number, array: string[]) => boolean;
193
- }
194
- type CopyGlobs = string[];
195
- interface WeappWebConfig {
196
- /**
197
- * @description 是否启用浏览器端运行时集成
198
- * @default false
199
- * @example
200
- * enable: true
201
- */
202
- enable?: boolean;
203
- /**
204
- * @description Web 侧项目根目录(即 index.html 所在目录)
205
- * @default 项目根目录
206
- * @example
207
- * root: 'web'
208
- */
209
- root?: string;
210
- /**
211
- * @description 小程序源码目录(相对于 `root`),默认与 `weapp.srcRoot` 保持一致
212
- * @example
213
- * srcDir: 'src'
214
- */
215
- srcDir?: string;
216
- /**
217
- * @description Web 构建产物输出目录;相对路径基于 `root`
218
- * @default "dist/web"
219
- * @example
220
- * outDir: 'dist/web'
221
- */
222
- outDir?: string;
223
- /**
224
- * @description 传递给 `weappWebPlugin` 的额外参数(不包含 `srcDir`)
225
- * @example
226
- * pluginOptions: { runtime: { executionMode: 'safe' } }
227
- */
228
- pluginOptions?: Partial<Omit<WeappWebPluginOptions, 'srcDir'>>;
229
- /**
230
- * @description 额外合并到 Web 构建中的 Vite 内联配置
231
- * @example
232
- * vite: { server: { host: true } }
233
- */
234
- vite?: InlineConfig;
235
- }
236
- interface WeappLibEntryContext {
237
- name: string;
238
- input: string;
239
- }
240
- type WeappLibFileName = string | ((context: WeappLibEntryContext) => string);
241
- type WeappLibComponentJson = boolean | 'auto' | ((context: WeappLibEntryContext) => Record<string, any>);
242
- interface WeappLibInternalDtsOptions {
243
- /**
244
- * @description internal 方案使用的 tsconfig 路径(false 表示不加载)
245
- */
246
- tsconfig?: string | false;
247
- /**
248
- * @description internal 方案的 compilerOptions
249
- */
250
- compilerOptions?: CompilerOptions;
251
- /**
252
- * @description internal 方案的 vueCompilerOptions
253
- */
254
- vueCompilerOptions?: Record<string, any>;
255
- }
256
- interface WeappLibVueTscOptions {
257
- /**
258
- * @description 额外合并到 vue-tsc 的 tsconfig(浅合并)
259
- */
260
- tsconfig?: Record<string, any>;
261
- /**
262
- * @description 传递给 vue-tsc 的 compilerOptions
263
- */
264
- compilerOptions?: CompilerOptions;
265
- /**
266
- * @description 传递给 vue-tsc 的 vueCompilerOptions
267
- */
268
- vueCompilerOptions?: Record<string, any>;
269
- }
270
- interface WeappLibDtsOptions {
271
- /**
272
- * @description 是否启用 lib 产物的 dts
273
- * @default true
274
- */
275
- enabled?: boolean;
276
- /**
277
- * @description Vue SFC dts 生成方式
278
- * @default 'internal'
279
- */
280
- mode?: 'internal' | 'vue-tsc';
281
- /**
282
- * @description internal 方案的配置
283
- */
284
- internal?: WeappLibInternalDtsOptions;
285
- /**
286
- * @description 透传给 rolldown-plugin-dts 的配置(内置字段会被覆盖)
287
- */
288
- rolldown?: Options;
289
- /**
290
- * @description 透传给 vue-tsc 的配置(会合并到临时 tsconfig)
291
- */
292
- vueTsc?: WeappLibVueTscOptions;
293
- }
294
- interface WeappLibConfig {
295
- /**
296
- * @description 入口配置,支持 string/array/record 形式
297
- * @example
298
- * entry: 'components/button/index.ts'
299
- * @example
300
- * entry: ['components/button/index.ts', 'utils/index.ts']
301
- * @example
302
- * entry: { button: 'components/button/index.ts' }
303
- */
304
- entry: string | string[] | Record<string, string>;
305
- /**
306
- * @description 库源码根目录,默认沿用 `weapp.srcRoot`
307
- */
308
- root?: string;
309
- /**
310
- * @description 输出目录,默认沿用 `build.outDir`
311
- */
312
- outDir?: string;
313
- /**
314
- * @description 是否保持输出路径与源码路径一致
315
- * @default true
316
- */
317
- preservePath?: boolean;
318
- /**
319
- * @description 自定义 JS 产物路径(不含扩展名)
320
- */
321
- fileName?: WeappLibFileName;
322
- /**
323
- * @description 自动生成组件 JSON 配置
324
- * @default 'auto'
325
- */
326
- componentJson?: WeappLibComponentJson;
327
- /**
328
- * @description 是否生成 lib 产物的 dts
329
- * @default true
330
- * @example
331
- * dts: false
332
- * @example
333
- * dts: { enabled: false }
334
- * @example
335
- * dts: { mode: 'vue-tsc' }
336
- * @example
337
- * dts: { rolldown: { tsconfigRaw: { compilerOptions: { declarationMap: true } } } }
338
- * @example
339
- * dts: { vueTsc: { compilerOptions: { declarationMap: true } } }
340
- * @example
341
- * dts: { internal: { compilerOptions: { declarationMap: true } } }
342
- */
343
- dts?: boolean | WeappLibDtsOptions;
344
- }
345
- interface AutoImportComponents {
346
- /**
347
- * 自动导入组件
348
- */
349
- globs?: string[];
350
- /**
351
- * 自动导入组件解析器
352
- */
353
- resolvers?: Resolver[];
354
- /**
355
- * 自动导入组件清单输出路径,默认输出到 `vite.config.ts` 同级目录的 `auto-import-components.json`
356
- * - `true` 或未指定: 按默认路径输出
357
- * - 传入字符串: 指定输出路径 (支持绝对/相对路径)
358
- * - `false`: 不生成清单文件
359
- */
360
- output?: string | boolean;
361
- /**
362
- * 生成 WXML 组件 props 类型声明文件。
363
- * - `true`: 输出到 `vite.config.ts` 同级目录的 `typed-components.d.ts`
364
- * - 传入字符串: 自定义输出路径 (支持绝对/相对路径)
365
- * - `false` 或未配置: 不生成类型文件
366
- */
367
- typedComponents?: boolean | string;
368
- /**
369
- * 生成 VS Code HTML customData 用于模板补全。
370
- * - `true`: 输出到 `vite.config.ts` 同级目录的 `mini-program.html-data.json`
371
- * - 传入字符串: 自定义输出路径 (支持绝对/相对路径)
372
- * - `false` 或未配置: 不生成 customData
373
- */
374
- htmlCustomData?: boolean | string;
375
- /**
376
- * 生成 Vue SFC 模板补全用的组件类型声明文件(`components.d.ts`)。
377
- * - `true`: 输出到 `vite.config.ts` 同级目录的 `components.d.ts`
378
- * - 传入字符串: 自定义输出路径 (支持绝对/相对路径)
379
- * - `false` 或未配置: 不生成类型文件
380
- */
381
- vueComponents?: boolean | string;
382
- /**
383
- * 生成 `components.d.ts` 时使用的运行时模块名(`declare module 'xxx'`)。
384
- * - 默认 `'vue'`
385
- * - 使用 wevu 并设置 `vueCompilerOptions.lib = "wevu"` 时请改为 `'wevu'`
386
- */
387
- vueComponentsModule?: string;
388
- }
389
- type AutoImportComponentsOption = AutoImportComponents | false;
390
- type EnhanceWxmlOptions = ScanWxmlOptions & HandleWxmlOptions;
391
- interface ScanWxmlOptions {
392
- excludeComponent?: (tagName: string) => boolean;
393
- platform?: MpPlatform;
394
- }
395
- interface HandleWxmlOptions {
396
- removeComment?: boolean;
397
- transformEvent?: boolean;
398
- scriptModuleExtension?: string;
399
- scriptModuleTag?: string;
400
- templateExtension?: string;
401
- }
402
- interface EnhanceOptions {
403
- /**
404
- * 增强:wxml
405
- */
406
- wxml?: boolean | (Partial<Omit<EnhanceWxmlOptions, 'platform'>>);
407
- /**
408
- * 增强:wxs
409
- */
410
- wxs?: boolean;
411
- /**
412
- * 自动导入小程序组件
413
- */
414
- autoImportComponents?: AutoImportComponentsOption;
415
- }
416
- interface BuildNpmPackageMeta {
417
- name: string;
418
- entry: InputOption;
419
- }
420
- interface NpmSubPackageConfig {
421
- /**
422
- * @description 分包本地 npm 依赖范围
423
- *
424
- * 当声明该字段后,会为对应分包输出本地 `miniprogram_npm`,
425
- * 并将分包内命中的 npm 引用本地化到该目录。
426
- */
427
- dependencies?: (string | RegExp)[];
428
- }
429
- interface NpmMainPackageConfig {
430
- /**
431
- * @description 主包 `miniprogram_npm` 依赖输出范围
432
- * - `undefined`: 默认行为,按根 `package.json.dependencies` 全量输出到主包
433
- * - `false`: 禁止输出主包 `miniprogram_npm`
434
- * - `string[] | RegExp[]`: 仅输出命中的依赖到主包
435
- *
436
- * 适用于依赖只希望落在特定分包 `miniprogram_npm` 的场景,
437
- * 需配合 `weapp.npm.subPackages.<root>.dependencies` 显式声明各分包依赖集。
438
- */
439
- dependencies?: false | (string | RegExp)[];
440
- }
441
- type JsFormat = 'cjs' | 'esm';
442
- type SharedChunkStrategy = 'hoist' | 'duplicate';
443
- type SharedChunkMode = 'common' | 'path' | 'inline';
444
- type SharedChunkDynamicImports = 'preserve' | 'inline';
445
- interface SharedChunkOverride {
446
- test: string | RegExp;
447
- mode: SharedChunkMode;
448
- }
449
- type JsonMergeStage = 'defaults' | 'json-block' | 'auto-using-components' | 'component-generics' | 'macro' | 'emit' | 'merge-existing';
450
- interface JsonMergeContext {
451
- filename?: string;
452
- kind?: 'app' | 'page' | 'component' | 'unknown';
453
- stage: JsonMergeStage;
454
- }
455
- type JsonMergeFunction = (target: Record<string, any>, source: Record<string, any>, context: JsonMergeContext) => Record<string, any> | void;
456
- type JsonMergeStrategy = 'deep' | 'assign' | 'replace' | JsonMergeFunction;
457
- interface JsonConfig {
458
- /**
459
- * @description 产物 JSON 默认值(用于 app/page/component)
460
- */
461
- defaults?: {
462
- app?: Record<string, any>;
463
- page?: Record<string, any>;
464
- component?: Record<string, any>;
465
- };
466
- /**
467
- * @description JSON 合并策略
468
- * - `deep`: 深合并(默认)
469
- * - `assign`: 浅合并(Object.assign)
470
- * - `replace`: 直接替换
471
- * - `function`: 自定义合并函数
472
- */
473
- mergeStrategy?: JsonMergeStrategy;
474
- }
475
- interface ChunksConfig {
476
- /**
477
- * @description 控制跨分包共享代码的输出策略
478
- * - `duplicate`: 默认策略,将共享代码复制到各自的分包中
479
- * - `hoist`: 将共享代码提炼到主包中
480
- * @default 'duplicate'
481
- */
482
- sharedStrategy?: SharedChunkStrategy;
483
- /**
484
- * @description 控制共享模块的输出形态
485
- * - `common`: 默认策略,复用模块会被抽到 common.js
486
- * - `path`: 共享模块按源码相对路径输出(无 common.js)
487
- * - `inline`: 禁用共享 chunk,复用模块将内联到引用方
488
- * @default 'common'
489
- */
490
- sharedMode?: SharedChunkMode;
491
- /**
492
- * @description 针对特定模块/目录覆盖共享输出策略,支持 glob 或正则表达式。
493
- * 匹配基于 srcRoot 的相对路径或绝对路径。
494
- */
495
- sharedOverrides?: SharedChunkOverride[];
496
- /**
497
- * @description 当 sharedMode 为 `path` 时,用于计算输出路径的根目录(相对 cwd)。
498
- * @default srcRoot
499
- */
500
- sharedPathRoot?: string;
501
- /**
502
- * @description 动态 import 的处理方式
503
- * - `preserve`: 保持独立 chunk
504
- * - `inline`: 尝试内联动态 import
505
- * @default 'preserve'
506
- */
507
- dynamicImports?: SharedChunkDynamicImports;
508
- /**
509
- * @description 是否输出分包优化日志,帮助确认共享模块被复制或回退的位置
510
- * @default true
511
- */
512
- logOptimization?: boolean;
513
- /**
514
- * @description 强制按分包复制的模块匹配规则。当共享模块的直接导入方命中这些规则时,
515
- * 其「主包」身份会被忽略,继续沿用 duplicate 策略。支持字符串或正则表达式,默认基于 srcRoot 的相对路径匹配。
516
- */
517
- forceDuplicatePatterns?: (string | RegExp)[];
518
- /**
519
- * @description 当共享模块复制后的冗余体积(字节)超过该阈值时输出警告。设置为 0 或 undefined 则禁用。
520
- * @default 524288 (约 512 KB)
521
- */
522
- duplicateWarningBytes?: number;
523
- }
524
- interface MultiPlatformConfig {
525
- /**
526
- * @description 是否启用多平台 project.config 解析
527
- * @default true
528
- * @example
529
- * enabled: true
530
- */
531
- enabled?: boolean;
532
- /**
533
- * @description 平台 project.config 目录根(实际读取 `${root}/${platform}/<platformConfigFile>`)
534
- * @default 'config'
535
- * @example
536
- * projectConfigRoot: 'config'
537
- */
538
- projectConfigRoot?: string;
539
- }
540
- interface WeappMcpConfig {
541
- /**
542
- * @description 是否启用 MCP 能力
543
- * @default true
544
- */
545
- enabled?: boolean;
546
- /**
547
- * @description 是否在 weapp-vite CLI 启动时自动拉起 MCP HTTP 服务
548
- * @default false
549
- */
550
- autoStart?: boolean;
551
- /**
552
- * @description MCP HTTP 服务监听主机
553
- * @default '127.0.0.1'
554
- */
555
- host?: string;
556
- /**
557
- * @description MCP HTTP 服务监听端口
558
- * @default 3088
559
- */
560
- port?: number;
561
- /**
562
- * @description MCP HTTP 接口路径
563
- * @default '/mcp'
564
- */
565
- endpoint?: string;
566
- }
567
- interface WeappViteConfig {
568
- /**
569
- * 应用入口目录(`app.json` 所在目录)。
570
- * 默认 js 模板在根目录 `.`,ts 模板在 `miniprogram` 目录;
571
- * 你也可以把所有代码放在 `src` 目录下,并设置此选项为 `src`。
572
- * @default '.'
573
- * @example
574
- * srcRoot: 'src'
575
- */
576
- srcRoot?: string;
577
- /**
578
- * @description 是否启用自动路由模块 (`weapp-vite/auto-routes`)
579
- * 默认关闭,需要显式启用后才会扫描 `pages/` 目录并生成路由清单。
580
- * @default false
581
- * @example
582
- * autoRoutes: true
583
- */
584
- autoRoutes?: boolean;
585
- /**
586
- * @description 插件入口目录 (plugin.json 所在的目录)
587
- * @default undefined
588
- * @example
589
- * pluginRoot: 'plugin'
590
- */
591
- pluginRoot?: string;
592
- /**
593
- * @description 日志输出配置(全局 + 按 tag 细分)
594
- * @example
595
- * logger: { level: 'info', tags: { build: true } }
596
- */
597
- logger?: LoggerConfig;
598
- /**
599
- * @description 主包/分包体积告警阈值(字节)。
600
- * 构建结束后会始终输出主包与各分包的体积报告;
601
- * 当某个包体积超过该阈值时,会额外输出警告。
602
- * 设置为 0 或 undefined 可关闭告警,但不会关闭体积报告。
603
- * @default 2097152 (2 MB)
604
- * @example
605
- * packageSizeWarningBytes: 2 * 1024 * 1024
606
- */
607
- packageSizeWarningBytes?: number;
608
- /**
609
- * @group json 配置
610
- * 文件引入别名
611
- * @example
612
- * jsonAlias: {
613
- * '@': '/src',
614
- * }
615
- */
616
- jsonAlias?: AliasOptions;
617
- /**
618
- *
619
- * @group 构建 npm
620
- */
621
- npm?: {
622
- /**
623
- * @description 是否开启构建 npm 功能, 默认为 true
624
- * @default true
625
- * @example
626
- * enable: true
627
- */
628
- enable?: boolean;
629
- /**
630
- * @description 是否开启缓存,默认为 true
631
- * @default true
632
- * @example
633
- * cache: true
634
- */
635
- cache?: boolean;
636
- /**
637
- * @description 主包本地 npm 构建配置
638
- */
639
- mainPackage?: NpmMainPackageConfig;
640
- /**
641
- * @description 分包本地 npm 构建配置
642
- *
643
- * 配置后,命中的分包会输出自己的 `miniprogram_npm`,
644
- * 并将分包内命中的 npm 引用本地化到分包目录。
645
- */
646
- subPackages?: Record<string, NpmSubPackageConfig>;
647
- /**
648
- * @description 构建 npm 的配置,可传入 Vite 的库模式配置,让不同的包走不同的配置
649
- * - 返回值中的 `build.outDir` 同时影响二次 bundle 的依赖与直接复制 `miniprogram` 产物的依赖
650
- * @example
651
- * buildOptions: (options, pkg) => {
652
- * if (pkg.name === 'my-lib') return { ...options, minify: false }
653
- * }
654
- */
655
- buildOptions?: (options: NpmBuildOptions, pkgMeta: BuildNpmPackageMeta) => NpmBuildOptions | undefined;
656
- /**
657
- * @description 支付宝平台 npm 依赖输出模式
658
- * - `node_modules`: 输出到 dist/node_modules(默认,贴近支付宝 npm 管理语义)
659
- * - `miniprogram_npm`: 输出到 dist/miniprogram_npm(兼容微信风格目录)
660
- * @default 'node_modules'
661
- */
662
- alipayNpmMode?: AlipayNpmMode;
663
- };
664
- /**
665
- * @group 生成脚手架配置
666
- * 生成器(weapp-vite generate)相关配置
667
- * @example
668
- * generate: { dirs: { page: 'src/pages' } }
669
- */
670
- generate?: GenerateOptions;
671
- /**
672
- * @group 插件集成
673
- * 传递给内置 [`vite-tsconfig-paths`](https://www.npmjs.com/package/vite-tsconfig-paths) 插件的参数
674
- * - 传入 `false` 可显式禁用该插件(当项目没有 `paths/baseUrl` 时建议关闭以提速)
675
- * @example
676
- * tsconfigPaths: { projects: ['tsconfig.json'] }
677
- */
678
- tsconfigPaths?: PluginOptions | false;
679
- /**
680
- * @group 分包配置
681
- * 分包是否独立的 rollup 编译上下文
682
- * 默认情况下,当一个分包设置了 independent: true 之后会默认启用
683
- * 可以设置 key: 为 root, value: {independent:true} 来强制启用 独立的 rollup 编译上下文
684
- */
685
- subPackages?: Record<string, Pick<SubPackage, 'independent' | 'inlineConfig'> & {
686
- autoImportComponents?: AutoImportComponentsOption;
687
- /** 分包文件变更时是否强制重新生成共享样式产物,默认启用 */
688
- watchSharedStyles?: boolean;
689
- /**
690
- * 分包共享样式入口,支持传入一个或多个 `wxss`/`css` 文件路径
691
- * - 相对路径默认基于当前分包的 `root`
692
- * - 也可以传入绝对路径或相对 `srcRoot` 的路径
693
- * - 支持传入对象配置 `scope`/`include`/`exclude` 精准控制注入范围
694
- * @example
695
- * styles: [
696
- * 'styles/shared.wxss',
697
- * { path: 'styles/sub.wxss', scope: 'page' },
698
- * ]
699
- */
700
- styles?: SubPackageStyleConfigEntry | SubPackageStyleConfigEntry[];
701
- }>;
702
- /**
703
- * 需要被额外包括的资源
704
- * 默认情况下包括大部分的图片资源格式
705
- * @example
706
- * copy: ['static/**\\/*']
707
- */
708
- copy?: CopyOptions;
709
- /**
710
- * @group Web 运行时
711
- * 浏览器端运行时相关配置
712
- * @example
713
- * web: { enabled: true, srcDir: 'src', outDir: 'dist/web' }
714
- */
715
- web?: WeappWebConfig;
716
- /**
717
- * @group 库模式
718
- * 用于构建组件库或小程序模块的 lib 模式配置
719
- */
720
- lib?: WeappLibConfig;
721
- /**
722
- * @description 额外的 wxml 文件
723
- * 把这个方法,扫描到的 `wxml` 添加到额外的 `wxml` 文件列表, **处理** 之后输出到最终的产物中
724
- * @param wxmlFilePath
725
- * @returns boolean
726
- * @example
727
- * isAdditionalWxml: (file) => file.includes('custom')
728
- */
729
- isAdditionalWxml?: (wxmlFilePath: string) => boolean;
730
- /**
731
- * @description 编译目标平台
732
- * @ignore
733
- */
734
- platform?: MpPlatform;
735
- /**
736
- * @description 多平台 project.config 支持
737
- * - `true` 等价于 `{ enabled: true, projectConfigRoot: 'config' }`
738
- * - 启用后必须通过 CLI `--platform` 指定目标小程序平台
739
- * @example
740
- * multiPlatform: true
741
- * @example
742
- * multiPlatform: { enabled: true, projectConfigRoot: 'config' }
743
- */
744
- multiPlatform?: boolean | MultiPlatformConfig;
745
- /**
746
- * @description 生成的 JS 模块格式
747
- * - `cjs`: 输出 CommonJS
748
- * - `esm`: 输出 ESM,需要在微信开发者工具中启用「ES6 转 ES5」
749
- * @default 'cjs'
750
- * @example
751
- * jsFormat: 'cjs'
752
- */
753
- jsFormat?: JsFormat;
754
- /**
755
- * @description 是否启用基于 `@swc/core` 的 ES5 降级(仅支持 `jsFormat: 'cjs'`)
756
- * @default false
757
- * @example
758
- * es5: true
759
- */
760
- es5?: boolean;
761
- wxml?: EnhanceOptions['wxml'];
762
- /**
763
- * 增强:wxs
764
- */
765
- wxs?: EnhanceOptions['wxs'];
766
- /**
767
- * 自动导入小程序组件
768
- */
769
- autoImportComponents?: AutoImportComponentsOption;
770
- /**
771
- * @deprecated 请改用顶层的 `wxml`、`wxs` 与 `autoImportComponents`
772
- * 增强配置
773
- */
774
- enhance?: EnhanceOptions;
775
- debug?: {
776
- watchFiles?: (watchFiles: string[], subPackageMeta?: SubPackageMetaValue) => void;
777
- resolveId?: (id: string, subPackageMeta?: SubPackageMetaValue) => void;
778
- load?: (id: string, subPackageMeta?: SubPackageMetaValue) => void;
779
- inspect?: WrapPluginOptions;
780
- };
781
- /**
782
- * @description 开发服务器相关配置
783
- */
784
- hmr?: {
785
- /**
786
- * @description HMR 期间共享 chunk 的处理策略
787
- * - `full`: 每次更新都重新产出全部 entry(最稳定,速度较慢)
788
- * - `auto`: 仅在共享 chunk 可能被部分覆盖时回退到 full(稳定与速度折中)
789
- * - `off`: 仅更新变更 entry(最快,但可能导致共享 chunk 导出不一致)
790
- * @default 'auto'
791
- */
792
- sharedChunks?: 'full' | 'auto' | 'off';
793
- /**
794
- * @description Dev 构建结束后触碰 app.wxss 以触发微信开发者工具热重载
795
- * - `true`: 总是启用
796
- * - `false`: 关闭
797
- * - `auto`: 检测到安装 weapp-tailwindcss 时启用
798
- * @default 'auto'
799
- */
800
- touchAppWxss?: boolean | 'auto';
801
- };
802
- /**
803
- * @description 构建 worker 配置
804
- */
805
- worker?: {
806
- /**
807
- * @description 构建 worker 的入口
808
- */
809
- entry?: string | string[];
810
- };
811
- /**
812
- * @description Vue 单文件组件支持配置
813
- */
814
- vue?: {
815
- /**
816
- * @description 是否启用 Vue 支持
817
- * @default true
818
- */
819
- enable?: boolean;
820
- /**
821
- * @description 模板编译选项
822
- */
823
- template?: {
824
- /**
825
- * @description 是否移除注释
826
- * @default true
827
- */
828
- removeComments?: boolean;
829
- /**
830
- * @description 是否简化空白符
831
- * @default true
832
- */
833
- simplifyWhitespace?: boolean;
834
- /**
835
- * @description 作用域插槽编译策略
836
- * - `auto`: 自动选择最小可用的 scoped slot 方案
837
- * - `augmented`: 强制使用增强方案
838
- * - `off`: 关闭 scoped slot 编译(仅保留原生 slot,不支持 slot props)
839
- * @default 'auto'
840
- */
841
- scopedSlotsCompiler?: 'auto' | 'augmented' | 'off';
842
- /**
843
- * @description 是否仅在 slot 传递作用域参数时生成 scoped slot 组件
844
- * - `true`: 仅对带作用域参数的 v-slot 生成 scoped slot 组件
845
- * - `false`: 所有 v-slot 都生成 scoped slot 组件(旧行为)
846
- * @default true
847
- */
848
- scopedSlotsRequireProps?: boolean;
849
- /**
850
- * @description v-for 下 scoped slot 多实例模式
851
- * @default true
852
- */
853
- slotMultipleInstance?: boolean;
854
- /**
855
- * @description class/style 绑定运行时
856
- * - `auto`: 平台支持 WXS 时优先 WXS,否则回退 JS
857
- * - `wxs`: 强制使用 WXS(不可用时回退 JS 并告警)
858
- * - `js`: 强制使用 JS(默认;用于获得更稳定的一致性)
859
- * @default 'js'
860
- */
861
- classStyleRuntime?: 'auto' | 'wxs' | 'js';
862
- /**
863
- * @description 对象字面量 v-bind 编译模式
864
- * - `runtime`: 通过运行时中间变量绑定(默认,当前行为)
865
- * - `inline`: 直接内联输出对象字面量(会在插值两侧补空格以避免 `{{{`)
866
- * @default 'runtime'
867
- */
868
- objectLiteralBindMode?: 'runtime' | 'inline';
869
- /**
870
- * @description Mustache 插值输出风格
871
- * - `compact`: 紧凑输出(`{{expr}}`,默认,当前行为)
872
- * - `spaced`: 空格友好输出(`{{ expr }}`)
873
- * @default 'compact'
874
- */
875
- mustacheInterpolation?: 'compact' | 'spaced';
876
- /**
877
- * @description 是否复用 class/style WXS 运行时(主包与非独立分包共享,独立分包各自生成)
878
- * @default true
879
- */
880
- classStyleWxsShared?: boolean;
881
- };
882
- /**
883
- * @description 是否自动导入 Vue 组件
884
- */
885
- autoImport?: boolean;
886
- };
887
- /**
888
- * @description wevu 运行时默认值(编译期注入)
889
- */
890
- wevu?: {
891
- /**
892
- * @description wevu 预设配置
893
- * - `performance`:开启性能向默认项(如 patch + suspendWhenHidden + diagnostics=fallback + dev 高频告警),并默认启用 autoSetDataPick(可显式覆盖)
894
- */
895
- preset?: 'performance';
896
- /**
897
- * @description wevu createApp/defineComponent 默认值
898
- */
899
- defaults?: WevuDefaults;
900
- /**
901
- * @description 自动从编译后的模板表达式推导渲染相关顶层 key,并注入到组件/页面的 `setData.pick`
902
- * @default false
903
- */
904
- autoSetDataPick?: boolean;
905
- };
906
- /**
907
- * @description 全局注入 @wevu/api 的 wpi 实例
908
- * - enabled 为 true 时会在 App 入口注入 wpi
909
- * - replaceWx 为 true 时会用 wpi 替换全局 wx/my 以及当前平台全局对象
910
- * @default { enabled: false, replaceWx: false, globalName: 'wpi' }
911
- * @example
912
- * injectWeapi: { enabled: true, replaceWx: false }
913
- */
914
- injectWeapi?: boolean | {
915
- /**
916
- * @description 是否启用全局注入
917
- * @default false
918
- */
919
- enabled?: boolean;
920
- /**
921
- * @description 是否使用 wpi 替换全局 wx/my 以及当前平台全局对象
922
- * @default false
923
- */
924
- replaceWx?: boolean;
925
- /**
926
- * @description 全局变量名
927
- * @default 'wpi'
928
- */
929
- globalName?: string;
930
- };
931
- /**
932
- * @description MCP 服务配置
933
- * - `false`:完全关闭 MCP(包含自动启动)
934
- * - `true`:启用默认 MCP 配置
935
- * - `object`:细粒度配置
936
- * @default { enabled: true, autoStart: false, host: '127.0.0.1', port: 3088, endpoint: '/mcp' }
937
- * @example
938
- * mcp: false
939
- * @example
940
- * mcp: { enabled: true, autoStart: false }
941
- * @example
942
- * mcp: { host: '127.0.0.1', port: 3199, endpoint: '/mcp' }
943
- */
944
- mcp?: boolean | WeappMcpConfig;
945
- /**
946
- * @description 共享代码拆分策略配置
947
- */
948
- chunks?: ChunksConfig;
949
- /**
950
- * @description JSON 产物合并配置
951
- */
952
- json?: JsonConfig;
953
- }
954
- type UserConfig$1 = UserConfig$2 & {
955
- weapp?: WeappViteConfig;
956
- };
957
- interface ProjectConfig {
958
- miniprogramRoot?: string;
959
- srcMiniprogramRoot?: string;
960
- smartProgramRoot?: string;
961
- setting?: {
962
- packNpmManually?: boolean;
963
- packNpmRelationList?: {
964
- packageJsonPath: string;
965
- miniprogramNpmDistDir: string;
966
- }[];
967
- };
968
- }
969
- interface SubPackageMetaValue {
970
- entries: string[];
971
- subPackage: SubPackage;
972
- autoImportComponents?: AutoImportComponentsOption;
973
- styleEntries?: SubPackageStyleEntry[];
974
- watchSharedStyles?: boolean;
975
- }
976
-
977
- interface WxmlDep {
978
- tagName: string;
979
- start: number;
980
- end: number;
981
- quote: string | null | undefined;
982
- name: string;
983
- value: string;
984
- attrs: Record<string, string>;
985
- }
986
- interface ScanComponentItem {
987
- start: number;
988
- end: number;
989
- }
990
- type ComponentsMap = Record<string, ScanComponentItem[]>;
991
-
992
- interface BaseEntry {
993
- path: string;
994
- jsonPath?: string;
995
- json?: object;
996
- type: 'app' | 'page' | 'component' | (string & {});
997
- }
998
- type Entry = AppEntry | PageEntry | ComponentEntry;
999
- /**
1000
- * 应用入口 js + json
1001
- */
1002
- interface AppEntry extends BaseEntry {
1003
- type: 'app';
1004
- themeJsonPath?: string;
1005
- themeJson?: Theme;
1006
- sitemapJsonPath?: string;
1007
- sitemapJson?: Sitemap;
1008
- json: App;
1009
- jsonPath: string;
1010
- }
1011
- /**
1012
- * 页面入口 js + wxml
1013
- */
1014
- interface PageEntry extends BaseEntry {
1015
- type: 'page';
1016
- templatePath: string;
1017
- json?: Page;
1018
- }
1019
- /**
1020
- * 组件入口 js + wxml + json + json.component === true
1021
- */
1022
- interface ComponentEntry extends BaseEntry {
1023
- type: 'component';
1024
- templatePath: string;
1025
- json: Component;
1026
- jsonPath: string;
1027
- }
1028
- type EntryJsonFragment = Omit<BaseEntry, 'path' | 'type'>;
1029
-
1030
- interface BuildOptions {
1031
- skipNpm?: boolean;
1032
- }
1033
- interface BuildService {
1034
- queue: PQueue;
1035
- build: (options?: BuildOptions) => Promise<RolldownOutput | RolldownOutput[] | RolldownWatcher>;
1036
- buildIndependentBundle: (root: string, meta: SubPackageMetaValue) => Promise<RolldownOutput>;
1037
- getIndependentOutput: (root: string) => RolldownOutput | undefined;
1038
- invalidateIndependentOutput: (root: string) => void;
1039
- }
1040
-
1041
- interface OutputExtensions {
1042
- js: string;
1043
- json: string;
1044
- wxml: string;
1045
- wxss: string;
1046
- wxs?: string;
1047
- }
1048
-
1049
- interface LoadConfigOptions {
1050
- cwd: string;
1051
- isDev: boolean;
1052
- mode: string;
1053
- inlineConfig?: InlineConfig;
1054
- configFile?: string;
1055
- cliPlatform?: string;
1056
- projectConfigPath?: string;
1057
- }
1058
- interface LoadConfigResult {
1059
- config: InlineConfig;
1060
- aliasEntries: ResolvedAlias[];
1061
- outputExtensions: OutputExtensions;
1062
- packageJson: PackageJson;
1063
- relativeSrcRoot: (p: string) => string;
1064
- cwd: string;
1065
- isDev: boolean;
1066
- mode: string;
1067
- chunksConfigured?: boolean;
1068
- projectConfig: Record<string, any>;
1069
- projectConfigPath?: string;
1070
- projectPrivateConfigPath?: string;
1071
- mpDistRoot: string;
1072
- weappLib?: ResolvedWeappLibConfig;
1073
- weappLibOutputMap?: Map<string, string>;
1074
- packageJsonPath: string;
1075
- platform: MpPlatform;
1076
- srcRoot: string;
1077
- configFilePath?: string;
1078
- currentSubPackageRoot?: string;
1079
- weappWeb?: ResolvedWeappWebConfig;
1080
- }
1081
- interface ResolvedWeappLibConfig {
1082
- enabled: boolean;
1083
- entry: WeappLibConfig['entry'];
1084
- root: string;
1085
- outDir?: string;
1086
- preservePath: boolean;
1087
- fileName?: WeappLibFileName;
1088
- componentJson: WeappLibComponentJson;
1089
- dts: WeappLibDtsOptions;
1090
- source?: WeappLibConfig;
1091
- }
1092
- interface PackageInfo {
1093
- name: string;
1094
- version: string | undefined;
1095
- rootPath: string;
1096
- packageJsonPath: string;
1097
- packageJson: PackageJson;
1098
- }
1099
- interface ConfigService {
1100
- options: LoadConfigResult;
1101
- outputExtensions: OutputExtensions;
1102
- defineEnv: Record<string, any>;
1103
- packageManager: DetectResult;
1104
- packageInfo: PackageInfo;
1105
- setDefineEnv: (key: string, value: any) => void;
1106
- load: (options?: Partial<LoadConfigOptions>) => Promise<LoadConfigResult>;
1107
- mergeWorkers: (...configs: Partial<InlineConfig>[]) => InlineConfig;
1108
- merge: (subPackageMeta?: SubPackageMetaValue, ...configs: Partial<InlineConfig | undefined>[]) => InlineConfig;
1109
- mergeWeb: (...configs: Partial<InlineConfig | undefined>[]) => InlineConfig | undefined;
1110
- mergeInlineConfig: (...configs: Partial<InlineConfig>[]) => InlineConfig;
1111
- readonly defineImportMetaEnv: Record<string, any>;
1112
- readonly cwd: string;
1113
- readonly isDev: boolean;
1114
- readonly mpDistRoot: string;
1115
- readonly outDir: string;
1116
- readonly inlineConfig: InlineConfig;
1117
- readonly weappViteConfig: NonNullable<InlineConfig['weapp']>;
1118
- readonly packageJson: PackageJson;
1119
- readonly projectConfig: Record<string, any>;
1120
- readonly projectConfigPath?: string;
1121
- readonly projectPrivateConfigPath?: string;
1122
- readonly srcRoot: string;
1123
- readonly pluginRoot: string | undefined;
1124
- readonly absolutePluginRoot: string | undefined;
1125
- readonly absolutePluginOutputRoot: string | undefined;
1126
- readonly absoluteSrcRoot: string;
1127
- readonly mode: string;
1128
- readonly aliasEntries: ResolvedAlias[];
1129
- readonly platform: MpPlatform;
1130
- readonly configFilePath?: string;
1131
- readonly weappWebConfig?: ResolvedWeappWebConfig;
1132
- readonly weappLibConfig?: ResolvedWeappLibConfig;
1133
- readonly weappLibOutputMap?: Map<string, string>;
1134
- relativeCwd: (p: string) => string;
1135
- relativeSrcRoot: (p: string) => string;
1136
- relativeAbsoluteSrcRoot: (p: string) => string;
1137
- relativeOutputPath: (p: string) => string;
1138
- readonly currentSubPackageRoot?: string;
1139
- }
1140
- interface ResolvedWeappWebConfig {
1141
- enabled: boolean;
1142
- root: string;
1143
- srcDir: string;
1144
- outDir: string;
1145
- pluginOptions: Omit<WeappWebPluginOptions, 'srcDir'> & {
1146
- srcDir: string;
1147
- };
1148
- userConfig?: InlineConfig;
1149
- source?: WeappWebConfig;
1150
- }
1151
-
1152
- interface JsonResolvableEntry {
1153
- json?: any;
1154
- jsonPath?: string;
1155
- type?: 'app' | 'page' | 'component' | 'plugin';
1156
- }
1157
-
1158
- type HashInput = string | Buffer;
1159
- declare class FileCache<T extends object> {
1160
- cache: LRUCache<string, T>;
1161
- mtimeMap: Map<string, number>;
1162
- signatureMap: Map<string, string>;
1163
- constructor(max?: number);
1164
- get(id: string): T | undefined;
1165
- set(id: string, content: T): LRUCache<string, T, unknown>;
1166
- delete(id: string): boolean;
1167
- isInvalidate(id: string, options?: {
1168
- content?: HashInput;
1169
- checkMtime?: boolean;
1170
- mtimeMs?: number;
1171
- signature?: string;
1172
- }): Promise<boolean>;
1173
- }
1174
-
1175
- interface JsonService {
1176
- read: (filepath: string) => Promise<any>;
1177
- resolve: (entry: JsonResolvableEntry) => string | undefined;
1178
- cache: FileCache<any>;
1179
- }
1180
-
1181
- interface NpmService {
1182
- getDependenciesCacheFilePath: (key?: string) => string;
1183
- readonly dependenciesCacheHash: string;
1184
- isMiniprogramPackage: (pkg: PackageJson) => boolean;
1185
- shouldSkipBuild: (outDir: string, isOutdated: boolean) => Promise<boolean>;
1186
- writeDependenciesCache: (root?: string) => Promise<void>;
1187
- readDependenciesCache: (root?: string) => Promise<any>;
1188
- checkDependenciesCacheOutdate: (root?: string) => Promise<boolean>;
1189
- bundleBuild: (args: {
1190
- entry: InputOption;
1191
- name: string;
1192
- options?: NpmBuildOptions;
1193
- outDir: string;
1194
- }) => Promise<void>;
1195
- copyBuild: (args: {
1196
- from: string;
1197
- to: string;
1198
- name: string;
1199
- }) => Promise<void>;
1200
- buildPackage: (args: {
1201
- dep: string;
1202
- outDir: string;
1203
- options?: NpmBuildOptions;
1204
- isDependenciesCacheOutdate: boolean;
1205
- }) => Promise<void>;
1206
- getPackNpmRelationList: () => {
1207
- packageJsonPath: string;
1208
- miniprogramNpmDistDir: string;
1209
- }[];
1210
- build: (options?: NpmBuildOptions) => Promise<void>;
1211
- }
1212
-
1213
- interface Token {
1214
- start: number;
1215
- end: number;
1216
- value: string;
1217
- }
1218
-
1219
- interface RemovalRange {
1220
- start: number;
1221
- end: number;
1222
- }
1223
- interface WxmlToken {
1224
- components: ComponentsMap;
1225
- deps: WxmlDep[];
1226
- removalRanges: RemovalRange[];
1227
- commentTokens: Token[];
1228
- inlineWxsTokens: Token[];
1229
- wxsImportNormalizeTokens: Token[];
1230
- removeWxsLangAttrTokens: Token[];
1231
- templateImportNormalizeTokens: Token[];
1232
- scriptModuleTagTokens: Token[];
1233
- eventTokens: Token[];
1234
- directiveTokens?: Token[];
1235
- tagNameTokens?: Token[];
1236
- code: string;
1237
- }
1238
-
1239
- declare function scanWxml(wxml: string | Buffer, options?: ScanWxmlOptions): WxmlToken;
1240
- type ScanWxmlResult = ReturnType<typeof scanWxml>;
1241
-
1242
- interface LocalAutoImportMatch {
1243
- kind: 'local';
1244
- entry: ComponentEntry;
1245
- value: ResolvedValue;
1246
- }
1247
-
1248
- interface WatcherInstance {
1249
- close: () => void | Promise<void>;
1250
- }
1251
- interface SidecarWatcher {
1252
- close: () => void | Promise<void>;
1253
- }
1254
-
1255
- interface AutoRoutesCandidateState {
1256
- base: string;
1257
- files: Set<string>;
1258
- hasScript: boolean;
1259
- hasTemplate: boolean;
1260
- jsonPath?: string;
1261
- }
1262
- interface LibEntryState {
1263
- name: string;
1264
- input: string;
1265
- outputBase: string;
1266
- relativeBase: string;
1267
- }
1268
- interface RuntimeState {
1269
- autoRoutes: {
1270
- routes: AutoRoutes;
1271
- serialized: string;
1272
- moduleCode: string;
1273
- typedDefinition: string;
1274
- watchFiles: Set<string>;
1275
- watchDirs: Set<string>;
1276
- dirty: boolean;
1277
- initialized: boolean;
1278
- candidates: Map<string, AutoRoutesCandidateState>;
1279
- needsFullRescan: boolean;
1280
- };
1281
- autoImport: {
1282
- registry: Map<string, LocalAutoImportMatch>;
1283
- matcher?: (input: string) => boolean;
1284
- matcherKey: string;
1285
- };
1286
- build: {
1287
- queue: PQueue;
1288
- npmBuilt: boolean;
1289
- independent: {
1290
- outputs: Map<string, RolldownOutput>;
1291
- };
1292
- };
1293
- json: {
1294
- cache: FileCache<any>;
1295
- };
1296
- css: {
1297
- importerToDependencies: Map<string, Set<string>>;
1298
- dependencyToImporters: Map<string, Set<string>>;
1299
- };
1300
- watcher: {
1301
- rollupWatcherMap: Map<string, WatcherInstance>;
1302
- sidecarWatcherMap: Map<string, SidecarWatcher>;
1303
- };
1304
- wxml: {
1305
- depsMap: Map<string, Set<string>>;
1306
- tokenMap: Map<string, ScanWxmlResult>;
1307
- componentsMap: Map<string, ComponentsMap>;
1308
- cache: FileCache<ScanWxmlResult>;
1309
- emittedCode: Map<string, string>;
1310
- };
1311
- scan: {
1312
- subPackageMap: Map<string, SubPackageMetaValue>;
1313
- independentSubPackageMap: Map<string, SubPackageMetaValue>;
1314
- appEntry?: AppEntry;
1315
- pluginJson?: Plugin;
1316
- pluginJsonPath?: string;
1317
- isDirty: boolean;
1318
- independentDirtyRoots: Set<string>;
1319
- };
1320
- lib: {
1321
- enabled: boolean;
1322
- entries: Map<string, LibEntryState>;
1323
- };
1324
- config: {
1325
- packageInfo: PackageInfo;
1326
- defineEnv: Record<string, any>;
1327
- packageManager: DetectResult;
1328
- options: LoadConfigResult;
1329
- };
1330
- }
1331
-
1332
- interface ScanService {
1333
- appEntry?: AppEntry;
1334
- pluginJson?: Plugin;
1335
- pluginJsonPath?: string;
1336
- subPackageMap: Map<string, SubPackageMetaValue>;
1337
- independentSubPackageMap: Map<string, SubPackageMetaValue>;
1338
- loadAppEntry: () => Promise<AppEntry>;
1339
- loadSubPackages: () => SubPackageMetaValue[];
1340
- isMainPackageFileName: (fileName: string) => boolean;
1341
- readonly workersOptions: App['workers'] | undefined;
1342
- readonly workersDir: string | undefined;
1343
- markDirty: () => void;
1344
- markIndependentDirty: (root: string) => void;
1345
- drainIndependentDirtyRoots: () => string[];
1346
- }
1347
-
1348
- interface WatcherService {
1349
- rollupWatcherMap: Map<string, WatcherInstance>;
1350
- sidecarWatcherMap: Map<string, SidecarWatcher>;
1351
- getRollupWatcher: (root?: string) => WatcherInstance | undefined;
1352
- setRollupWatcher: (watcher: WatcherInstance, root?: string) => void;
1353
- close: (root?: string) => void;
1354
- closeAll: () => void;
1355
- }
1356
-
1357
- interface WebService {
1358
- readonly devServer?: ViteDevServer;
1359
- isEnabled: () => boolean;
1360
- startDevServer: () => Promise<ViteDevServer | undefined>;
1361
- build: () => Promise<Awaited<ReturnType<typeof build>> | undefined>;
1362
- close: () => Promise<void>;
1363
- }
1364
-
1365
- interface WxmlService {
1366
- depsMap: Map<string, Set<string>>;
1367
- tokenMap: Map<string, ScanWxmlResult>;
1368
- wxmlComponentsMap: Map<string, ComponentsMap>;
1369
- addDeps: (filepath: string, deps?: string[]) => Promise<void>;
1370
- getAllDeps: () => Set<string>;
1371
- clearAll: () => void;
1372
- analyze: (wxml: string) => ScanWxmlResult;
1373
- scan: (filepath: string) => Promise<ScanWxmlResult | undefined>;
1374
- setWxmlComponentsMap: (absPath: string, components: ComponentsMap) => void;
1375
- }
1376
-
1377
- interface ResolverAutoImportMatch {
1378
- kind: 'resolver';
1379
- value: ResolvedValue;
1380
- }
1381
- type AutoImportMatch = LocalAutoImportMatch | ResolverAutoImportMatch;
1382
- interface AutoImportService {
1383
- reset: () => void;
1384
- registerPotentialComponent: (filePath: string) => Promise<void>;
1385
- removePotentialComponent: (filePath: string) => void;
1386
- resolve: (componentName: string, importerBaseName?: string) => AutoImportMatch | undefined;
1387
- filter: (id: string, meta?: SubPackageMetaValue) => boolean;
1388
- getRegisteredLocalComponents: () => LocalAutoImportMatch[];
1389
- awaitManifestWrites: () => Promise<void>;
1390
- }
1391
-
1392
- type AutoRoutesFileEvent = ChangeEvent | 'rename';
1393
-
1394
- interface AutoRoutesService {
1395
- ensureFresh: () => Promise<void>;
1396
- markDirty: () => void;
1397
- getSnapshot: () => AutoRoutes;
1398
- getReference: () => AutoRoutes;
1399
- getSignature: () => string;
1400
- getModuleCode: () => string;
1401
- getWatchFiles: () => Iterable<string>;
1402
- getWatchDirectories: () => Iterable<string>;
1403
- isRouteFile: (filePath: string) => boolean;
1404
- handleFileChange: (filePath: string, event?: AutoRoutesFileEvent) => Promise<void>;
1405
- isInitialized: () => boolean;
1406
- isEnabled: () => boolean;
1407
- }
1408
-
1409
- type BuildTarget = 'app' | 'plugin';
1410
- interface CompilerContext {
1411
- runtimeState: RuntimeState;
1412
- configService: ConfigService;
1413
- npmService: NpmService;
1414
- wxmlService: WxmlService;
1415
- jsonService: JsonService;
1416
- watcherService: WatcherService;
1417
- webService: WebService;
1418
- autoImportService: AutoImportService;
1419
- autoRoutesService: AutoRoutesService;
1420
- buildService: BuildService;
1421
- scanService: ScanService;
1422
- currentBuildTarget?: BuildTarget;
1423
- }
1424
-
1425
- interface WeappVitePluginApi {
1426
- ctx: CompilerContext;
1427
- }
1428
- type ChangeEvent = 'create' | 'update' | 'delete';
1429
-
1430
- type ReturnSelf<T> = (config: T) => T;
1431
- type ConfigFn<T> = T | ((ctx: CompilerContext) => T);
1432
- type DefineJsonFn<T> = ReturnSelf<ConfigFn<T>>;
1433
- /**
1434
- * @description 定义 app.json(支持直接对象或函数形式)
1435
- */
1436
- declare const defineAppJson: DefineJsonFn<App>;
1437
- /**
1438
- * @description 定义 page.json(支持直接对象或函数形式)
1439
- */
1440
- declare const definePageJson: DefineJsonFn<Page>;
1441
- /**
1442
- * @description 定义 component.json(支持直接对象或函数形式)
1443
- */
1444
- declare const defineComponentJson: DefineJsonFn<Component>;
1445
- /**
1446
- * @description 定义 sitemap.json(支持直接对象或函数形式)
1447
- */
1448
- declare const defineSitemapJson: DefineJsonFn<Sitemap>;
1449
- /**
1450
- * @description 定义 theme.json(支持直接对象或函数形式)
1451
- */
1452
- declare const defineThemeJson: DefineJsonFn<Theme>;
1453
-
1454
- /**
1455
- * @description weapp-vite 的用户配置(扩展 Vite UserConfig)
1456
- */
1457
- type UserConfig = UserConfig$2 & {
1458
- weapp?: WeappViteConfig;
1459
- };
1460
- type UserConfigFnNoEnvPlain<T extends UserConfig = UserConfig> = () => T;
1461
- type UserConfigFnNoEnv<T extends UserConfig = UserConfig> = () => T | Promise<T>;
1462
- type UserConfigFnObjectPlain<T extends UserConfig = UserConfig> = (env: ConfigEnv) => T;
1463
- type UserConfigFnObject<T extends UserConfig = UserConfig> = (env: ConfigEnv) => T;
1464
- type UserConfigFnPromise<T extends UserConfig = UserConfig> = (env: ConfigEnv) => Promise<T>;
1465
- type UserConfigFn<T extends UserConfig = UserConfig> = (env: ConfigEnv) => T | Promise<T>;
1466
- type UserConfigLoose = UserConfig & Record<string, any>;
1467
- type UserConfigExport<T extends UserConfig = UserConfig> = T | Promise<T> | UserConfigFnNoEnv<T> | UserConfigFnObject<T> | UserConfigFnPromise<T> | UserConfigFn<T>;
1468
- declare module 'vite' {
1469
- interface UserConfig {
1470
- weapp?: WeappViteConfig;
1471
- }
1472
- }
1473
- /**
1474
- * @description 为 weapp-vite 配置提供类型提示与推断
1475
- * @description 注意:同步回调重载需要放在 Promise/联合返回前面,
1476
- * 这样 `vite.config.ts` 里对象字面量属性(如 `weapp.srcRoot`)才能保留上下文类型,
1477
- * 才能在编辑器中正确显示 JSDoc 与支持跳转。
1478
- */
1479
- declare function defineConfig(config: UserConfig): UserConfig;
1480
- declare function defineConfig(config: Promise<UserConfig>): Promise<UserConfig>;
1481
- declare function defineConfig(config: UserConfigFnNoEnvPlain): UserConfigFnNoEnvPlain;
1482
- declare function defineConfig(config: UserConfigFnNoEnv): UserConfigFnNoEnv;
1483
- declare function defineConfig(config: UserConfigFnObjectPlain): UserConfigFnObjectPlain;
1484
- declare function defineConfig(config: UserConfigFnPromise): UserConfigFnPromise;
1485
- declare function defineConfig(config: UserConfigFn): UserConfigFn;
1486
- declare function defineConfig(config: UserConfigLoose): UserConfigLoose;
1487
-
1488
- export { type GenerateTemplateInlineSource as $, type Alias as A, type BaseEntry as B, type CompilerContext as C, type BuildNpmPackageMeta as D, type ChangeEvent as E, type ChunksConfig as F, type ComponentEntry as G, type ComponentsMap as H, type CopyGlobs as I, type CopyOptions as J, type EnhanceOptions as K, type LoadConfigOptions as L, type EnhanceWxmlOptions as M, type Entry as N, type EntryJsonFragment as O, type GenerateDirsOptions as P, type GenerateExtensionsOptions as Q, type GenerateFileType as R, type GenerateFilenamesOptions as S, type GenerateOptions as T, type UserConfig as U, type GenerateTemplate as V, WEAPP_VITE_HOST_NAME as W, type GenerateTemplateContext as X, type GenerateTemplateEntry as Y, type GenerateTemplateFactory as Z, type GenerateTemplateFileSource as _, type UserConfigExport as a, type GenerateTemplateScope as a0, type GenerateTemplatesConfig as a1, type HandleWxmlOptions as a2, type JsFormat as a3, type JsonConfig as a4, type JsonMergeContext as a5, type JsonMergeFunction as a6, type JsonMergeStage as a7, type JsonMergeStrategy as a8, type MpPlatform as a9, type WeappLibVueTscOptions as aA, type WeappVitePluginApi as aB, type WeappWebConfig as aC, type WxmlDep as aD, type MultiPlatformConfig as aa, type NpmBuildOptions as ab, type NpmMainPackageConfig as ac, type NpmSubPackageConfig as ad, type PageEntry as ae, type ProjectConfig as af, type ResolvedAlias as ag, type ScanComponentItem as ah, type ScanWxmlOptions as ai, type SharedChunkDynamicImports as aj, type SharedChunkMode as ak, type SharedChunkOverride as al, type SharedChunkStrategy as am, type SubPackage as an, type SubPackageMetaValue as ao, type SubPackageStyleConfigEntry as ap, type SubPackageStyleConfigObject as aq, type SubPackageStyleEntry as ar, type SubPackageStyleScope as as, type UserConfig$1 as at, type WeappLibComponentJson as au, type WeappLibConfig as av, type WeappLibDtsOptions as aw, type WeappLibEntryContext as ax, type WeappLibFileName as ay, type WeappLibInternalDtsOptions as az, type UserConfigFn as b, type UserConfigFnNoEnv as c, type UserConfigFnNoEnvPlain as d, type UserConfigFnObject as e, type UserConfigFnObjectPlain as f, type UserConfigFnPromise as g, type WeappViteConfig as h, type WeappViteHostMeta as i, type WeappViteRuntime as j, applyWeappViteHostMeta as k, createWeappViteHostMeta as l, defineAppJson as m, defineComponentJson as n, defineConfig as o, definePageJson as p, defineSitemapJson as q, defineThemeJson as r, isWeappViteHost as s, resolveWeappViteHostMeta as t, type WeappMcpConfig as u, type AliasOptions as v, type AlipayNpmMode as w, type AppEntry as x, type AutoImportComponents as y, type AutoImportComponentsOption as z };