weapp-vite 5.3.0 → 5.5.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.
@@ -1,10 +1,12 @@
1
- import { InlineConfig, UserConfig as UserConfig$1, UserConfigFnObject, UserConfigExport } from 'vite';
2
- import { GenerateType, Component, Theme, Sitemap, App, Page, Plugin } from '@weapp-core/schematics';
3
1
  import { InputOption, RolldownOutput, RolldownWatcher } from 'rolldown';
2
+ import { InlineConfig, UserConfig as UserConfig$1, ViteDevServer, build, UserConfigFnObject, UserConfigExport } from 'vite';
3
+ import { A as AutoRoutes } from './routes-C9hKJjXs.cjs';
4
+ import { a as Resolver, R as ResolvedValue } from './types-g_G_na7r.cjs';
4
5
  import { Options } from 'tsdown';
6
+ import { GenerateType, Component, Theme, Sitemap, App, Page, Plugin } from '@weapp-core/schematics';
7
+ import { WeappWebPluginOptions } from '@weapp-vite/web';
5
8
  import { WrapPluginOptions } from 'vite-plugin-performance';
6
9
  import { PluginOptions } from 'vite-tsconfig-paths';
7
- import { R as Resolver, a as ResolvedValue } from './types-3q1Qq6Fe.cjs';
8
10
  import PQueue from 'p-queue';
9
11
  import { DetectResult } from 'package-manager-detector';
10
12
  import { PackageJson } from 'pkg-types';
@@ -45,7 +47,7 @@ interface AliasOptions {
45
47
  [find: string]: string;
46
48
  };
47
49
  }
48
- type MpPlatform = 'weapp' | 'alipay' | 'tt';
50
+ type MpPlatform = 'weapp' | 'alipay' | 'tt' | 'swan' | 'jd' | 'xhs';
49
51
  interface SubPackage {
50
52
  pages: string[];
51
53
  root: string;
@@ -116,6 +118,35 @@ interface CopyOptions {
116
118
  filter?: (filePath: string, index: number, array: string[]) => boolean;
117
119
  }
118
120
  type CopyGlobs = string[];
121
+ interface WeappWebConfig {
122
+ /**
123
+ * @description 是否启用浏览器端运行时集成
124
+ * @default false
125
+ */
126
+ enable?: boolean;
127
+ /**
128
+ * @description Web 侧项目根目录(即 index.html 所在目录)
129
+ * @default 项目根目录
130
+ */
131
+ root?: string;
132
+ /**
133
+ * @description 小程序源码目录(相对于 `root`),默认与 `weapp.srcRoot` 保持一致
134
+ */
135
+ srcDir?: string;
136
+ /**
137
+ * @description Web 构建产物输出目录;相对路径基于 `root`
138
+ * @default "dist-web"
139
+ */
140
+ outDir?: string;
141
+ /**
142
+ * @description 传递给 `weappWebPlugin` 的额外参数(不包含 `srcDir`)
143
+ */
144
+ pluginOptions?: Partial<Omit<WeappWebPluginOptions, 'srcDir'>>;
145
+ /**
146
+ * @description 额外合并到 Web 构建中的 Vite 内联配置
147
+ */
148
+ vite?: InlineConfig;
149
+ }
119
150
  interface AutoImportComponents {
120
151
  /**
121
152
  * 自动导入组件
@@ -132,6 +163,20 @@ interface AutoImportComponents {
132
163
  * - `false`: 不生成清单文件
133
164
  */
134
165
  output?: string | boolean;
166
+ /**
167
+ * 生成 WXML 组件 props 类型声明文件。
168
+ * - `true`: 输出到 `vite.config.ts` 同级目录的 `typed-components.d.ts`
169
+ * - 传入字符串: 自定义输出路径 (支持绝对/相对路径)
170
+ * - `false` 或未配置: 不生成类型文件
171
+ */
172
+ typedComponents?: boolean | string;
173
+ /**
174
+ * 生成 VS Code HTML customData 用于模板补全。
175
+ * - `true`: 输出到 `vite.config.ts` 同级目录的 `mini-program.html-data.json`
176
+ * - 传入字符串: 自定义输出路径 (支持绝对/相对路径)
177
+ * - `false` 或未配置: 不生成 customData
178
+ */
179
+ htmlCustomData?: boolean | string;
135
180
  }
136
181
  type EnhanceWxmlOptions = ScanWxmlOptions & HandleWxmlOptions;
137
182
  interface ScanWxmlOptions {
@@ -160,6 +205,17 @@ interface BuildNpmPackageMeta {
160
205
  name: string;
161
206
  entry: InputOption;
162
207
  }
208
+ type JsFormat = 'cjs' | 'esm';
209
+ type SharedChunkStrategy = 'hoist' | 'duplicate';
210
+ interface ChunksConfig {
211
+ /**
212
+ * @description 控制跨分包共享代码的输出策略
213
+ * - `duplicate`: 默认策略,将共享代码复制到各自的分包中
214
+ * - `hoist`: 将共享代码提炼到主包中
215
+ * @default 'duplicate'
216
+ */
217
+ sharedStrategy?: SharedChunkStrategy;
218
+ }
163
219
  interface WeappViteConfig {
164
220
  /**
165
221
  * @description 应用入口目录 (app.json 所在的目录)
@@ -167,6 +223,12 @@ interface WeappViteConfig {
167
223
  * @default '.'
168
224
  */
169
225
  srcRoot?: string;
226
+ /**
227
+ * @description 是否启用自动路由模块 (`weapp-vite/auto-routes`)
228
+ * 默认关闭,需要显式启用后才会扫描 `pages/` 目录并生成路由清单。
229
+ * @default false
230
+ */
231
+ autoRoutes?: boolean;
170
232
  /**
171
233
  * @description 插件入口目录 (plugin.json 所在的目录)
172
234
  * @default undefined
@@ -221,6 +283,11 @@ interface WeappViteConfig {
221
283
  * 默认情况下包括大部分的图片资源格式
222
284
  */
223
285
  copy?: CopyOptions;
286
+ /**
287
+ * @group Web 运行时
288
+ * 浏览器端运行时相关配置
289
+ */
290
+ web?: WeappWebConfig;
224
291
  /**
225
292
  * @description 额外的 wxml 文件
226
293
  * 把这个方法,扫描到的 `wxml` 添加到额外的 `wxml` 文件列表, **处理** 之后输出到最终的产物中
@@ -234,6 +301,28 @@ interface WeappViteConfig {
234
301
  */
235
302
  platform?: MpPlatform;
236
303
  /**
304
+ * @description 生成的 JS 模块格式
305
+ * - `cjs`: 输出 CommonJS
306
+ * - `esm`: 输出 ESM,需要在微信开发者工具中启用「ES6 转 ES5」
307
+ * @default 'cjs'
308
+ */
309
+ jsFormat?: JsFormat;
310
+ /**
311
+ * @description 是否启用基于 `@swc/core` 的 ES5 降级(仅支持 `jsFormat: 'cjs'`)
312
+ * @default false
313
+ */
314
+ es5?: boolean;
315
+ wxml?: EnhanceOptions['wxml'];
316
+ /**
317
+ * wxs 增强
318
+ */
319
+ wxs?: EnhanceOptions['wxs'];
320
+ /**
321
+ * 自动导入小程序组件
322
+ */
323
+ autoImportComponents?: AutoImportComponents;
324
+ /**
325
+ * @deprecated 请改用顶层的 `wxml`、`wxs` 与 `autoImportComponents`
237
326
  * 增强配置
238
327
  */
239
328
  enhance?: EnhanceOptions;
@@ -252,6 +341,10 @@ interface WeappViteConfig {
252
341
  */
253
342
  entry?: string | string[];
254
343
  };
344
+ /**
345
+ * @description 共享代码拆分策略配置
346
+ */
347
+ chunks?: ChunksConfig;
255
348
  }
256
349
  type UserConfig = UserConfig$1 & {
257
350
  weapp?: WeappViteConfig;
@@ -364,6 +457,7 @@ interface LoadConfigResult {
364
457
  srcRoot: string;
365
458
  configFilePath?: string;
366
459
  currentSubPackageRoot?: string;
460
+ weappWeb?: ResolvedWeappWebConfig;
367
461
  }
368
462
  interface PackageInfo {
369
463
  name: string;
@@ -382,6 +476,7 @@ interface ConfigService {
382
476
  load: (options?: Partial<LoadConfigOptions>) => Promise<LoadConfigResult>;
383
477
  mergeWorkers: (...configs: Partial<InlineConfig>[]) => InlineConfig;
384
478
  merge: (subPackageMeta?: SubPackageMetaValue, ...configs: Partial<InlineConfig | undefined>[]) => InlineConfig;
479
+ mergeWeb: (...configs: Partial<InlineConfig | undefined>[]) => InlineConfig | undefined;
385
480
  readonly defineImportMetaEnv: Record<string, any>;
386
481
  readonly cwd: string;
387
482
  readonly isDev: boolean;
@@ -399,11 +494,23 @@ interface ConfigService {
399
494
  readonly aliasEntries: ResolvedAlias[];
400
495
  readonly platform: MpPlatform;
401
496
  readonly configFilePath?: string;
497
+ readonly weappWebConfig?: ResolvedWeappWebConfig;
402
498
  relativeCwd: (p: string) => string;
403
499
  relativeSrcRoot: (p: string) => string;
404
500
  relativeAbsoluteSrcRoot: (p: string) => string;
405
501
  readonly currentSubPackageRoot?: string;
406
502
  }
503
+ interface ResolvedWeappWebConfig {
504
+ enabled: boolean;
505
+ root: string;
506
+ srcDir: string;
507
+ outDir: string;
508
+ pluginOptions: Omit<WeappWebPluginOptions, 'srcDir'> & {
509
+ srcDir: string;
510
+ };
511
+ userConfig?: InlineConfig;
512
+ source?: WeappWebConfig;
513
+ }
407
514
 
408
515
  type HashInput = string | Buffer;
409
516
  declare class FileCache<T extends object> {
@@ -495,6 +602,16 @@ interface SidecarWatcher {
495
602
  }
496
603
 
497
604
  interface RuntimeState {
605
+ autoRoutes: {
606
+ routes: AutoRoutes;
607
+ serialized: string;
608
+ moduleCode: string;
609
+ typedDefinition: string;
610
+ watchFiles: Set<string>;
611
+ watchDirs: Set<string>;
612
+ dirty: boolean;
613
+ initialized: boolean;
614
+ };
498
615
  autoImport: {
499
616
  registry: Map<string, LocalAutoImportMatch>;
500
617
  matcher?: (input: string) => boolean;
@@ -557,6 +674,14 @@ interface WatcherService {
557
674
  closeAll: () => void;
558
675
  }
559
676
 
677
+ interface WebService {
678
+ readonly devServer?: ViteDevServer;
679
+ isEnabled: () => boolean;
680
+ startDevServer: () => Promise<ViteDevServer | undefined>;
681
+ build: () => Promise<Awaited<ReturnType<typeof build>> | undefined>;
682
+ close: () => Promise<void>;
683
+ }
684
+
560
685
  interface WxmlService {
561
686
  depsMap: Map<string, Set<string>>;
562
687
  tokenMap: Map<string, ScanWxmlResult>;
@@ -584,6 +709,20 @@ interface AutoImportService {
584
709
  awaitManifestWrites: () => Promise<void>;
585
710
  }
586
711
 
712
+ interface AutoRoutesService {
713
+ ensureFresh: () => Promise<void>;
714
+ markDirty: () => void;
715
+ getSnapshot: () => AutoRoutes;
716
+ getReference: () => AutoRoutes;
717
+ getModuleCode: () => string;
718
+ getWatchFiles: () => Iterable<string>;
719
+ getWatchDirectories: () => Iterable<string>;
720
+ isRouteFile: (filePath: string) => boolean;
721
+ handleFileChange: (filePath: string, event?: ChangeEvent) => Promise<void>;
722
+ isInitialized: () => boolean;
723
+ isEnabled: () => boolean;
724
+ }
725
+
587
726
  interface CompilerContext {
588
727
  runtimeState: RuntimeState;
589
728
  configService: ConfigService;
@@ -591,11 +730,18 @@ interface CompilerContext {
591
730
  wxmlService: WxmlService;
592
731
  jsonService: JsonService;
593
732
  watcherService: WatcherService;
733
+ webService: WebService;
594
734
  autoImportService: AutoImportService;
735
+ autoRoutesService: AutoRoutesService;
595
736
  buildService: BuildService;
596
737
  scanService: ScanService;
597
738
  }
598
739
 
740
+ interface WeappVitePluginApi {
741
+ ctx: CompilerContext;
742
+ }
743
+ type ChangeEvent = 'create' | 'update' | 'delete';
744
+
599
745
  type ReturnSelf<T> = (config: T) => T;
600
746
  type ConfigFn<T> = T | ((ctx: CompilerContext) => T);
601
747
  type DefineJsonFn<T> = ReturnSelf<ConfigFn<T>>;
@@ -615,4 +761,4 @@ declare function defineConfig(config: Promise<UserConfig$1>): Promise<UserConfig
615
761
  declare function defineConfig(config: UserConfigFnObject): UserConfigFnObject;
616
762
  declare function defineConfig(config: UserConfigExport): UserConfigExport;
617
763
 
618
- export { type Alias as A, type BuildNpmPackageMeta as B, type CompilerContext as C, type ScanComponentItem as D, type EnhanceWxmlOptions as E, type ComponentsMap as F, type GenerateExtensionsOptions as G, type HandleWxmlOptions as H, type BaseEntry as I, type Entry as J, type AppEntry as K, type LoadConfigOptions as L, type MpPlatform as M, type PageEntry as N, type ComponentEntry as O, type ProjectConfig as P, type EntryJsonFragment as Q, type ResolvedAlias as R, type SubPackage as S, type UserConfig as U, type WeappViteConfig as W, defineAppJson as a, definePageJson as b, defineComponentJson as c, defineConfig as d, defineSitemapJson as e, defineThemeJson as f, type AliasOptions as g, type GenerateDirsOptions as h, type GenerateFilenamesOptions as i, type GenerateFileType as j, type GenerateTemplateContext as k, type GenerateTemplateFileSource as l, type GenerateTemplateInlineSource as m, type GenerateTemplateFactory as n, type GenerateTemplate as o, type GenerateTemplateEntry as p, type GenerateTemplateScope as q, type GenerateTemplatesConfig as r, type GenerateOptions as s, type CopyOptions as t, type CopyGlobs as u, type AutoImportComponents as v, type ScanWxmlOptions as w, type EnhanceOptions as x, type SubPackageMetaValue as y, type WxmlDep as z };
764
+ export { type Alias as A, type BuildNpmPackageMeta as B, type CompilerContext as C, type ChunksConfig as D, type EnhanceWxmlOptions as E, type SubPackageMetaValue as F, type GenerateExtensionsOptions as G, type HandleWxmlOptions as H, type WxmlDep as I, type JsFormat as J, type ScanComponentItem as K, type LoadConfigOptions as L, type MpPlatform as M, type ComponentsMap as N, type BaseEntry as O, type ProjectConfig as P, type Entry as Q, type ResolvedAlias as R, type SubPackage as S, type AppEntry as T, type UserConfig as U, type PageEntry as V, type WeappViteConfig as W, type ComponentEntry as X, type EntryJsonFragment as Y, type WeappVitePluginApi as Z, type ChangeEvent as _, defineAppJson as a, definePageJson as b, defineComponentJson as c, defineConfig as d, defineSitemapJson as e, defineThemeJson as f, type AliasOptions as g, type GenerateDirsOptions as h, type GenerateFilenamesOptions as i, type GenerateFileType as j, type GenerateTemplateContext as k, type GenerateTemplateFileSource as l, type GenerateTemplateInlineSource as m, type GenerateTemplateFactory as n, type GenerateTemplate as o, type GenerateTemplateEntry as p, type GenerateTemplateScope as q, type GenerateTemplatesConfig as r, type GenerateOptions as s, type CopyOptions as t, type CopyGlobs as u, type WeappWebConfig as v, type AutoImportComponents as w, type ScanWxmlOptions as x, type EnhanceOptions as y, type SharedChunkStrategy as z };
@@ -1,10 +1,12 @@
1
- import { InlineConfig, UserConfig as UserConfig$1, UserConfigFnObject, UserConfigExport } from 'vite';
2
- import { GenerateType, Component, Theme, Sitemap, App, Page, Plugin } from '@weapp-core/schematics';
3
1
  import { InputOption, RolldownOutput, RolldownWatcher } from 'rolldown';
2
+ import { InlineConfig, UserConfig as UserConfig$1, ViteDevServer, build, UserConfigFnObject, UserConfigExport } from 'vite';
3
+ import { A as AutoRoutes } from './routes-C9hKJjXs.js';
4
+ import { a as Resolver, R as ResolvedValue } from './types-g_G_na7r.js';
4
5
  import { Options } from 'tsdown';
6
+ import { GenerateType, Component, Theme, Sitemap, App, Page, Plugin } from '@weapp-core/schematics';
7
+ import { WeappWebPluginOptions } from '@weapp-vite/web';
5
8
  import { WrapPluginOptions } from 'vite-plugin-performance';
6
9
  import { PluginOptions } from 'vite-tsconfig-paths';
7
- import { R as Resolver, a as ResolvedValue } from './types-3q1Qq6Fe.js';
8
10
  import PQueue from 'p-queue';
9
11
  import { DetectResult } from 'package-manager-detector';
10
12
  import { PackageJson } from 'pkg-types';
@@ -45,7 +47,7 @@ interface AliasOptions {
45
47
  [find: string]: string;
46
48
  };
47
49
  }
48
- type MpPlatform = 'weapp' | 'alipay' | 'tt';
50
+ type MpPlatform = 'weapp' | 'alipay' | 'tt' | 'swan' | 'jd' | 'xhs';
49
51
  interface SubPackage {
50
52
  pages: string[];
51
53
  root: string;
@@ -116,6 +118,35 @@ interface CopyOptions {
116
118
  filter?: (filePath: string, index: number, array: string[]) => boolean;
117
119
  }
118
120
  type CopyGlobs = string[];
121
+ interface WeappWebConfig {
122
+ /**
123
+ * @description 是否启用浏览器端运行时集成
124
+ * @default false
125
+ */
126
+ enable?: boolean;
127
+ /**
128
+ * @description Web 侧项目根目录(即 index.html 所在目录)
129
+ * @default 项目根目录
130
+ */
131
+ root?: string;
132
+ /**
133
+ * @description 小程序源码目录(相对于 `root`),默认与 `weapp.srcRoot` 保持一致
134
+ */
135
+ srcDir?: string;
136
+ /**
137
+ * @description Web 构建产物输出目录;相对路径基于 `root`
138
+ * @default "dist-web"
139
+ */
140
+ outDir?: string;
141
+ /**
142
+ * @description 传递给 `weappWebPlugin` 的额外参数(不包含 `srcDir`)
143
+ */
144
+ pluginOptions?: Partial<Omit<WeappWebPluginOptions, 'srcDir'>>;
145
+ /**
146
+ * @description 额外合并到 Web 构建中的 Vite 内联配置
147
+ */
148
+ vite?: InlineConfig;
149
+ }
119
150
  interface AutoImportComponents {
120
151
  /**
121
152
  * 自动导入组件
@@ -132,6 +163,20 @@ interface AutoImportComponents {
132
163
  * - `false`: 不生成清单文件
133
164
  */
134
165
  output?: string | boolean;
166
+ /**
167
+ * 生成 WXML 组件 props 类型声明文件。
168
+ * - `true`: 输出到 `vite.config.ts` 同级目录的 `typed-components.d.ts`
169
+ * - 传入字符串: 自定义输出路径 (支持绝对/相对路径)
170
+ * - `false` 或未配置: 不生成类型文件
171
+ */
172
+ typedComponents?: boolean | string;
173
+ /**
174
+ * 生成 VS Code HTML customData 用于模板补全。
175
+ * - `true`: 输出到 `vite.config.ts` 同级目录的 `mini-program.html-data.json`
176
+ * - 传入字符串: 自定义输出路径 (支持绝对/相对路径)
177
+ * - `false` 或未配置: 不生成 customData
178
+ */
179
+ htmlCustomData?: boolean | string;
135
180
  }
136
181
  type EnhanceWxmlOptions = ScanWxmlOptions & HandleWxmlOptions;
137
182
  interface ScanWxmlOptions {
@@ -160,6 +205,17 @@ interface BuildNpmPackageMeta {
160
205
  name: string;
161
206
  entry: InputOption;
162
207
  }
208
+ type JsFormat = 'cjs' | 'esm';
209
+ type SharedChunkStrategy = 'hoist' | 'duplicate';
210
+ interface ChunksConfig {
211
+ /**
212
+ * @description 控制跨分包共享代码的输出策略
213
+ * - `duplicate`: 默认策略,将共享代码复制到各自的分包中
214
+ * - `hoist`: 将共享代码提炼到主包中
215
+ * @default 'duplicate'
216
+ */
217
+ sharedStrategy?: SharedChunkStrategy;
218
+ }
163
219
  interface WeappViteConfig {
164
220
  /**
165
221
  * @description 应用入口目录 (app.json 所在的目录)
@@ -167,6 +223,12 @@ interface WeappViteConfig {
167
223
  * @default '.'
168
224
  */
169
225
  srcRoot?: string;
226
+ /**
227
+ * @description 是否启用自动路由模块 (`weapp-vite/auto-routes`)
228
+ * 默认关闭,需要显式启用后才会扫描 `pages/` 目录并生成路由清单。
229
+ * @default false
230
+ */
231
+ autoRoutes?: boolean;
170
232
  /**
171
233
  * @description 插件入口目录 (plugin.json 所在的目录)
172
234
  * @default undefined
@@ -221,6 +283,11 @@ interface WeappViteConfig {
221
283
  * 默认情况下包括大部分的图片资源格式
222
284
  */
223
285
  copy?: CopyOptions;
286
+ /**
287
+ * @group Web 运行时
288
+ * 浏览器端运行时相关配置
289
+ */
290
+ web?: WeappWebConfig;
224
291
  /**
225
292
  * @description 额外的 wxml 文件
226
293
  * 把这个方法,扫描到的 `wxml` 添加到额外的 `wxml` 文件列表, **处理** 之后输出到最终的产物中
@@ -234,6 +301,28 @@ interface WeappViteConfig {
234
301
  */
235
302
  platform?: MpPlatform;
236
303
  /**
304
+ * @description 生成的 JS 模块格式
305
+ * - `cjs`: 输出 CommonJS
306
+ * - `esm`: 输出 ESM,需要在微信开发者工具中启用「ES6 转 ES5」
307
+ * @default 'cjs'
308
+ */
309
+ jsFormat?: JsFormat;
310
+ /**
311
+ * @description 是否启用基于 `@swc/core` 的 ES5 降级(仅支持 `jsFormat: 'cjs'`)
312
+ * @default false
313
+ */
314
+ es5?: boolean;
315
+ wxml?: EnhanceOptions['wxml'];
316
+ /**
317
+ * wxs 增强
318
+ */
319
+ wxs?: EnhanceOptions['wxs'];
320
+ /**
321
+ * 自动导入小程序组件
322
+ */
323
+ autoImportComponents?: AutoImportComponents;
324
+ /**
325
+ * @deprecated 请改用顶层的 `wxml`、`wxs` 与 `autoImportComponents`
237
326
  * 增强配置
238
327
  */
239
328
  enhance?: EnhanceOptions;
@@ -252,6 +341,10 @@ interface WeappViteConfig {
252
341
  */
253
342
  entry?: string | string[];
254
343
  };
344
+ /**
345
+ * @description 共享代码拆分策略配置
346
+ */
347
+ chunks?: ChunksConfig;
255
348
  }
256
349
  type UserConfig = UserConfig$1 & {
257
350
  weapp?: WeappViteConfig;
@@ -364,6 +457,7 @@ interface LoadConfigResult {
364
457
  srcRoot: string;
365
458
  configFilePath?: string;
366
459
  currentSubPackageRoot?: string;
460
+ weappWeb?: ResolvedWeappWebConfig;
367
461
  }
368
462
  interface PackageInfo {
369
463
  name: string;
@@ -382,6 +476,7 @@ interface ConfigService {
382
476
  load: (options?: Partial<LoadConfigOptions>) => Promise<LoadConfigResult>;
383
477
  mergeWorkers: (...configs: Partial<InlineConfig>[]) => InlineConfig;
384
478
  merge: (subPackageMeta?: SubPackageMetaValue, ...configs: Partial<InlineConfig | undefined>[]) => InlineConfig;
479
+ mergeWeb: (...configs: Partial<InlineConfig | undefined>[]) => InlineConfig | undefined;
385
480
  readonly defineImportMetaEnv: Record<string, any>;
386
481
  readonly cwd: string;
387
482
  readonly isDev: boolean;
@@ -399,11 +494,23 @@ interface ConfigService {
399
494
  readonly aliasEntries: ResolvedAlias[];
400
495
  readonly platform: MpPlatform;
401
496
  readonly configFilePath?: string;
497
+ readonly weappWebConfig?: ResolvedWeappWebConfig;
402
498
  relativeCwd: (p: string) => string;
403
499
  relativeSrcRoot: (p: string) => string;
404
500
  relativeAbsoluteSrcRoot: (p: string) => string;
405
501
  readonly currentSubPackageRoot?: string;
406
502
  }
503
+ interface ResolvedWeappWebConfig {
504
+ enabled: boolean;
505
+ root: string;
506
+ srcDir: string;
507
+ outDir: string;
508
+ pluginOptions: Omit<WeappWebPluginOptions, 'srcDir'> & {
509
+ srcDir: string;
510
+ };
511
+ userConfig?: InlineConfig;
512
+ source?: WeappWebConfig;
513
+ }
407
514
 
408
515
  type HashInput = string | Buffer;
409
516
  declare class FileCache<T extends object> {
@@ -495,6 +602,16 @@ interface SidecarWatcher {
495
602
  }
496
603
 
497
604
  interface RuntimeState {
605
+ autoRoutes: {
606
+ routes: AutoRoutes;
607
+ serialized: string;
608
+ moduleCode: string;
609
+ typedDefinition: string;
610
+ watchFiles: Set<string>;
611
+ watchDirs: Set<string>;
612
+ dirty: boolean;
613
+ initialized: boolean;
614
+ };
498
615
  autoImport: {
499
616
  registry: Map<string, LocalAutoImportMatch>;
500
617
  matcher?: (input: string) => boolean;
@@ -557,6 +674,14 @@ interface WatcherService {
557
674
  closeAll: () => void;
558
675
  }
559
676
 
677
+ interface WebService {
678
+ readonly devServer?: ViteDevServer;
679
+ isEnabled: () => boolean;
680
+ startDevServer: () => Promise<ViteDevServer | undefined>;
681
+ build: () => Promise<Awaited<ReturnType<typeof build>> | undefined>;
682
+ close: () => Promise<void>;
683
+ }
684
+
560
685
  interface WxmlService {
561
686
  depsMap: Map<string, Set<string>>;
562
687
  tokenMap: Map<string, ScanWxmlResult>;
@@ -584,6 +709,20 @@ interface AutoImportService {
584
709
  awaitManifestWrites: () => Promise<void>;
585
710
  }
586
711
 
712
+ interface AutoRoutesService {
713
+ ensureFresh: () => Promise<void>;
714
+ markDirty: () => void;
715
+ getSnapshot: () => AutoRoutes;
716
+ getReference: () => AutoRoutes;
717
+ getModuleCode: () => string;
718
+ getWatchFiles: () => Iterable<string>;
719
+ getWatchDirectories: () => Iterable<string>;
720
+ isRouteFile: (filePath: string) => boolean;
721
+ handleFileChange: (filePath: string, event?: ChangeEvent) => Promise<void>;
722
+ isInitialized: () => boolean;
723
+ isEnabled: () => boolean;
724
+ }
725
+
587
726
  interface CompilerContext {
588
727
  runtimeState: RuntimeState;
589
728
  configService: ConfigService;
@@ -591,11 +730,18 @@ interface CompilerContext {
591
730
  wxmlService: WxmlService;
592
731
  jsonService: JsonService;
593
732
  watcherService: WatcherService;
733
+ webService: WebService;
594
734
  autoImportService: AutoImportService;
735
+ autoRoutesService: AutoRoutesService;
595
736
  buildService: BuildService;
596
737
  scanService: ScanService;
597
738
  }
598
739
 
740
+ interface WeappVitePluginApi {
741
+ ctx: CompilerContext;
742
+ }
743
+ type ChangeEvent = 'create' | 'update' | 'delete';
744
+
599
745
  type ReturnSelf<T> = (config: T) => T;
600
746
  type ConfigFn<T> = T | ((ctx: CompilerContext) => T);
601
747
  type DefineJsonFn<T> = ReturnSelf<ConfigFn<T>>;
@@ -615,4 +761,4 @@ declare function defineConfig(config: Promise<UserConfig$1>): Promise<UserConfig
615
761
  declare function defineConfig(config: UserConfigFnObject): UserConfigFnObject;
616
762
  declare function defineConfig(config: UserConfigExport): UserConfigExport;
617
763
 
618
- export { type Alias as A, type BuildNpmPackageMeta as B, type CompilerContext as C, type ScanComponentItem as D, type EnhanceWxmlOptions as E, type ComponentsMap as F, type GenerateExtensionsOptions as G, type HandleWxmlOptions as H, type BaseEntry as I, type Entry as J, type AppEntry as K, type LoadConfigOptions as L, type MpPlatform as M, type PageEntry as N, type ComponentEntry as O, type ProjectConfig as P, type EntryJsonFragment as Q, type ResolvedAlias as R, type SubPackage as S, type UserConfig as U, type WeappViteConfig as W, defineAppJson as a, definePageJson as b, defineComponentJson as c, defineConfig as d, defineSitemapJson as e, defineThemeJson as f, type AliasOptions as g, type GenerateDirsOptions as h, type GenerateFilenamesOptions as i, type GenerateFileType as j, type GenerateTemplateContext as k, type GenerateTemplateFileSource as l, type GenerateTemplateInlineSource as m, type GenerateTemplateFactory as n, type GenerateTemplate as o, type GenerateTemplateEntry as p, type GenerateTemplateScope as q, type GenerateTemplatesConfig as r, type GenerateOptions as s, type CopyOptions as t, type CopyGlobs as u, type AutoImportComponents as v, type ScanWxmlOptions as w, type EnhanceOptions as x, type SubPackageMetaValue as y, type WxmlDep as z };
764
+ export { type Alias as A, type BuildNpmPackageMeta as B, type CompilerContext as C, type ChunksConfig as D, type EnhanceWxmlOptions as E, type SubPackageMetaValue as F, type GenerateExtensionsOptions as G, type HandleWxmlOptions as H, type WxmlDep as I, type JsFormat as J, type ScanComponentItem as K, type LoadConfigOptions as L, type MpPlatform as M, type ComponentsMap as N, type BaseEntry as O, type ProjectConfig as P, type Entry as Q, type ResolvedAlias as R, type SubPackage as S, type AppEntry as T, type UserConfig as U, type PageEntry as V, type WeappViteConfig as W, type ComponentEntry as X, type EntryJsonFragment as Y, type WeappVitePluginApi as Z, type ChangeEvent as _, defineAppJson as a, definePageJson as b, defineComponentJson as c, defineConfig as d, defineSitemapJson as e, defineThemeJson as f, type AliasOptions as g, type GenerateDirsOptions as h, type GenerateFilenamesOptions as i, type GenerateFileType as j, type GenerateTemplateContext as k, type GenerateTemplateFileSource as l, type GenerateTemplateInlineSource as m, type GenerateTemplateFactory as n, type GenerateTemplate as o, type GenerateTemplateEntry as p, type GenerateTemplateScope as q, type GenerateTemplatesConfig as r, type GenerateOptions as s, type CopyOptions as t, type CopyGlobs as u, type WeappWebConfig as v, type AutoImportComponents as w, type ScanWxmlOptions as x, type EnhanceOptions as y, type SharedChunkStrategy as z };
package/dist/config.d.cts CHANGED
@@ -1,11 +1,13 @@
1
1
  export { UserConfig, UserConfigExport, UserConfigFnObject } from 'vite';
2
- export { W as WeappViteConfig, a as defineAppJson, c as defineComponentJson, d as defineConfig, b as definePageJson, e as defineSitemapJson, f as defineThemeJson } from './config-j03AZAws.cjs';
2
+ export { W as WeappViteConfig, a as defineAppJson, c as defineComponentJson, d as defineConfig, b as definePageJson, e as defineSitemapJson, f as defineThemeJson } from './config-CzCzK7Jh.cjs';
3
3
  export { App, Component, Page, Sitemap, Theme } from '@weapp-core/schematics';
4
4
  import 'rolldown';
5
+ import './routes-C9hKJjXs.cjs';
6
+ import './types-g_G_na7r.cjs';
5
7
  import 'tsdown';
8
+ import '@weapp-vite/web';
6
9
  import 'vite-plugin-performance';
7
10
  import 'vite-tsconfig-paths';
8
- import './types-3q1Qq6Fe.cjs';
9
11
  import 'p-queue';
10
12
  import 'package-manager-detector';
11
13
  import 'pkg-types';
package/dist/config.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  export { UserConfig, UserConfigExport, UserConfigFnObject } from 'vite';
2
- export { W as WeappViteConfig, a as defineAppJson, c as defineComponentJson, d as defineConfig, b as definePageJson, e as defineSitemapJson, f as defineThemeJson } from './config-BMJAZP6e.js';
2
+ export { W as WeappViteConfig, a as defineAppJson, c as defineComponentJson, d as defineConfig, b as definePageJson, e as defineSitemapJson, f as defineThemeJson } from './config-DepC4j8j.js';
3
3
  export { App, Component, Page, Sitemap, Theme } from '@weapp-core/schematics';
4
4
  import 'rolldown';
5
+ import './routes-C9hKJjXs.js';
6
+ import './types-g_G_na7r.js';
5
7
  import 'tsdown';
8
+ import '@weapp-vite/web';
6
9
  import 'vite-plugin-performance';
7
10
  import 'vite-tsconfig-paths';
8
- import './types-3q1Qq6Fe.js';
9
11
  import 'p-queue';
10
12
  import 'package-manager-detector';
11
13
  import 'pkg-types';
package/dist/index.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkN2SUN4MXcjs = require('./chunk-N2SUN4MX.cjs');
3
+ var _chunkOWCDSB6Fcjs = require('./chunk-OWCDSB6F.cjs');
4
+ require('./chunk-5GG5TEGR.cjs');
4
5
 
5
6
 
6
7
  var _chunkDVVMF6NDcjs = require('./chunk-DVVMF6ND.cjs');
@@ -26,4 +27,4 @@ _chunkOS76JPG2cjs.init_cjs_shims.call(void 0, );
26
27
 
27
28
 
28
29
 
29
- exports.createCompilerContext = _chunkN2SUN4MXcjs.createCompilerContext; exports.defineAppJson = _chunkBT7FLFCCcjs.defineAppJson; exports.defineComponentJson = _chunkBT7FLFCCcjs.defineComponentJson; exports.defineConfig = _chunkDVVMF6NDcjs.defineConfig; exports.definePageJson = _chunkBT7FLFCCcjs.definePageJson; exports.defineSitemapJson = _chunkBT7FLFCCcjs.defineSitemapJson; exports.defineThemeJson = _chunkBT7FLFCCcjs.defineThemeJson;
30
+ exports.createCompilerContext = _chunkOWCDSB6Fcjs.createCompilerContext; exports.defineAppJson = _chunkBT7FLFCCcjs.defineAppJson; exports.defineComponentJson = _chunkBT7FLFCCcjs.defineComponentJson; exports.defineConfig = _chunkDVVMF6NDcjs.defineConfig; exports.definePageJson = _chunkBT7FLFCCcjs.definePageJson; exports.defineSitemapJson = _chunkBT7FLFCCcjs.defineSitemapJson; exports.defineThemeJson = _chunkBT7FLFCCcjs.defineThemeJson;
package/dist/index.d.cts CHANGED
@@ -1,12 +1,14 @@
1
- import { L as LoadConfigOptions, C as CompilerContext } from './config-j03AZAws.cjs';
2
- export { W as WeappViteConfig, a as defineAppJson, c as defineComponentJson, d as defineConfig, b as definePageJson, e as defineSitemapJson, f as defineThemeJson } from './config-j03AZAws.cjs';
1
+ import { L as LoadConfigOptions, C as CompilerContext } from './config-CzCzK7Jh.cjs';
2
+ export { W as WeappViteConfig, a as defineAppJson, c as defineComponentJson, d as defineConfig, b as definePageJson, e as defineSitemapJson, f as defineThemeJson } from './config-CzCzK7Jh.cjs';
3
3
  export { RolldownBuild, RolldownOptions, RolldownOutput, RolldownPlugin, RolldownPluginOption, WatchOptions as RolldownWatchOptions, RolldownWatcher } from 'rolldown';
4
4
  export { ConfigEnv, InlineConfig, Plugin, PluginOption, ResolvedConfig, UserConfig, UserConfigExport, UserConfigFnObject, ViteDevServer } from 'vite';
5
5
  export { App, Component, Page, Sitemap, Theme } from '@weapp-core/schematics';
6
+ import './routes-C9hKJjXs.cjs';
7
+ import './types-g_G_na7r.cjs';
6
8
  import 'tsdown';
9
+ import '@weapp-vite/web';
7
10
  import 'vite-plugin-performance';
8
11
  import 'vite-tsconfig-paths';
9
- import './types-3q1Qq6Fe.cjs';
10
12
  import 'p-queue';
11
13
  import 'package-manager-detector';
12
14
  import 'pkg-types';
package/dist/index.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- import { L as LoadConfigOptions, C as CompilerContext } from './config-BMJAZP6e.js';
2
- export { W as WeappViteConfig, a as defineAppJson, c as defineComponentJson, d as defineConfig, b as definePageJson, e as defineSitemapJson, f as defineThemeJson } from './config-BMJAZP6e.js';
1
+ import { L as LoadConfigOptions, C as CompilerContext } from './config-DepC4j8j.js';
2
+ export { W as WeappViteConfig, a as defineAppJson, c as defineComponentJson, d as defineConfig, b as definePageJson, e as defineSitemapJson, f as defineThemeJson } from './config-DepC4j8j.js';
3
3
  export { RolldownBuild, RolldownOptions, RolldownOutput, RolldownPlugin, RolldownPluginOption, WatchOptions as RolldownWatchOptions, RolldownWatcher } from 'rolldown';
4
4
  export { ConfigEnv, InlineConfig, Plugin, PluginOption, ResolvedConfig, UserConfig, UserConfigExport, UserConfigFnObject, ViteDevServer } from 'vite';
5
5
  export { App, Component, Page, Sitemap, Theme } from '@weapp-core/schematics';
6
+ import './routes-C9hKJjXs.js';
7
+ import './types-g_G_na7r.js';
6
8
  import 'tsdown';
9
+ import '@weapp-vite/web';
7
10
  import 'vite-plugin-performance';
8
11
  import 'vite-tsconfig-paths';
9
- import './types-3q1Qq6Fe.js';
10
12
  import 'p-queue';
11
13
  import 'package-manager-detector';
12
14
  import 'pkg-types';
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  createCompilerContext
3
- } from "./chunk-JGSE2EOU.mjs";
3
+ } from "./chunk-QCLEMTCV.mjs";
4
+ import "./chunk-T4MUKDMP.mjs";
4
5
  import {
5
6
  defineConfig
6
7
  } from "./chunk-HVMR6H5Z.mjs";
package/dist/json.d.cts CHANGED
@@ -1,11 +1,13 @@
1
1
  export { App, Component, Page, Sitemap, Theme } from '@weapp-core/schematics';
2
- export { a as defineAppJson, c as defineComponentJson, b as definePageJson, e as defineSitemapJson, f as defineThemeJson } from './config-j03AZAws.cjs';
3
- import 'vite';
2
+ export { a as defineAppJson, c as defineComponentJson, b as definePageJson, e as defineSitemapJson, f as defineThemeJson } from './config-CzCzK7Jh.cjs';
4
3
  import 'rolldown';
4
+ import 'vite';
5
+ import './routes-C9hKJjXs.cjs';
6
+ import './types-g_G_na7r.cjs';
5
7
  import 'tsdown';
8
+ import '@weapp-vite/web';
6
9
  import 'vite-plugin-performance';
7
10
  import 'vite-tsconfig-paths';
8
- import './types-3q1Qq6Fe.cjs';
9
11
  import 'p-queue';
10
12
  import 'package-manager-detector';
11
13
  import 'pkg-types';