weapp-vite
Version:
weapp-vite 一个现代化的小程序打包工具
877 lines (850 loc) • 29.2 kB
text/typescript
import { InlineConfig, UserConfig as UserConfig$1, ViteDevServer, build, UserConfigFnObject, UserConfigExport } from 'vite';
import { GenerateType, Component, Theme, Sitemap, App, Page, Plugin } from '@weapp-core/schematics';
import { WeappWebPluginOptions } from '@weapp-vite/web';
import { InputOption, RolldownOutput, RolldownWatcher } from 'rolldown';
import { WrapPluginOptions } from 'vite-plugin-performance';
import { PluginOptions } from 'vite-tsconfig-paths';
import { R as Resolver, a as ResolvedValue } from './types-3q1Qq6Fe.cjs';
import PQueue from 'p-queue';
import { DetectResult } from 'package-manager-detector';
import { PackageJson } from 'pkg-types';
import { Buffer } from 'node:buffer';
import { LRUCache } from 'lru-cache';
import { A as AutoRoutes } from './routes-C9hKJjXs.cjs';
type NpmBuildOptions = InlineConfig;
interface Alias {
find: string | RegExp;
replacement: string;
}
interface ResolvedAlias {
find: string | RegExp;
replacement: string;
}
interface AliasOptions {
/**
* @example
* ```js
entries: [
{
find: '@',
replacement: path.resolve(import.meta.dirname, 'components'),
},
],
* ```
这样你就可以在 json 里面使用:
```json
{
"usingComponents": {
"navigation-bar": "@/navigation-bar/navigation-bar",
"ice-avatar": "@/avatar/avatar"
}
}
```
* 详见[json别名](/guide/alias.html#json-别名)文档
*/
entries?: readonly Alias[] | {
[find: string]: string;
};
}
type MpPlatform = 'weapp' | 'alipay' | 'tt' | 'swan' | 'jd' | 'xhs';
interface SubPackage {
pages: string[];
root: string;
independent?: boolean;
entry?: string;
name?: string;
dependencies?: (string | RegExp)[];
inlineConfig?: Partial<InlineConfig>;
}
type SubPackageStyleScope = 'all' | 'pages' | 'components';
interface SubPackageStyleConfigObject {
/** 样式文件路径,可以是相对分包 root、相对 `srcRoot` 或绝对路径 */
source: string;
/**
* 作用范围快捷配置:
*
* - `all`: 默认值,分包内所有页面与组件都会引入
* - `pages`: 仅匹配分包 `pages/**`
* - `components`: 仅匹配分包 `components/**`
*
* 可结合 `include` / `exclude` 进一步细分范围
*/
scope?: SubPackageStyleScope;
/** 自定义包含路径,支持传入单个 glob 或数组,默认覆盖分包内所有文件 */
include?: string | string[];
/** 自定义排除路径,支持传入单个 glob 或数组 */
exclude?: string | string[];
}
type SubPackageStyleConfigEntry = string | SubPackageStyleConfigObject;
interface SubPackageStyleEntry {
/**
* 源配置字符串(便于诊断)
*/
source: string;
/**
* 原始样式文件的绝对路径
*/
absolutePath: string;
/**
* 相对于 `srcRoot` 的输出路径(已转换为目标平台样式后缀)
*/
outputRelativePath: string;
/**
* 源文件扩展名(包含 `.`)
*/
inputExtension: string;
/**
* 作用域快捷字段,便于诊断输出
*/
scope: SubPackageStyleScope;
/**
* 允许生效的 glob 列表(基于分包 root 的相对路径)
*/
include: string[];
/**
* 排除的 glob 列表(基于分包 root 的相对路径)
*/
exclude: string[];
}
type GenerateExtensionsOptions = Partial<{
js: 'js' | 'ts' | (string & {});
json: 'js' | 'ts' | 'json' | (string & {});
wxml: 'wxml' | (string & {});
wxss: 'wxss' | 'scss' | 'less' | 'css' | (string & {});
}>;
type GenerateDirsOptions = Partial<{
app: string;
page: string;
component: string;
}>;
type GenerateFilenamesOptions = Partial<{
app: string;
page: string;
component: string;
}>;
type GenerateFileType = 'js' | 'json' | 'wxml' | 'wxss';
interface GenerateTemplateContext {
type: GenerateType;
fileType: GenerateFileType;
fileName: string;
outDir: string;
extension: string;
cwd: string;
defaultCode?: string;
}
interface GenerateTemplateFileSource {
path: string;
}
interface GenerateTemplateInlineSource {
content: string;
}
type GenerateTemplateFactory = (context: GenerateTemplateContext) => string | Promise<string> | undefined;
type GenerateTemplate = string | GenerateTemplateFileSource | GenerateTemplateInlineSource | GenerateTemplateFactory;
type GenerateTemplateEntry = Partial<Record<GenerateFileType, GenerateTemplate>>;
type GenerateTemplateScope = GenerateType | 'shared';
type GenerateTemplatesConfig = Partial<Record<GenerateTemplateScope, GenerateTemplateEntry>>;
interface GenerateOptions {
/**
* 生成文件的扩展名
*/
extensions?: GenerateExtensionsOptions;
/**
* 默认生成文件的相对路径
*/
dirs?: GenerateDirsOptions;
/**
* 默认生成文件的名称
*/
filenames?: GenerateFilenamesOptions;
/**
* 自定义模板
*/
templates?: GenerateTemplatesConfig;
}
interface CopyOptions {
include?: CopyGlobs;
exclude?: CopyGlobs;
filter?: (filePath: string, index: number, array: string[]) => boolean;
}
type CopyGlobs = string[];
interface WeappWebConfig {
/**
* @description 是否启用浏览器端运行时集成
* @default false
*/
enable?: boolean;
/**
* @description Web 侧项目根目录(即 index.html 所在目录)
* @default 项目根目录
*/
root?: string;
/**
* @description 小程序源码目录(相对于 `root`),默认与 `weapp.srcRoot` 保持一致
*/
srcDir?: string;
/**
* @description Web 构建产物输出目录;相对路径基于 `root`
* @default "dist-web"
*/
outDir?: string;
/**
* @description 传递给 `weappWebPlugin` 的额外参数(不包含 `srcDir`)
*/
pluginOptions?: Partial<Omit<WeappWebPluginOptions, 'srcDir'>>;
/**
* @description 额外合并到 Web 构建中的 Vite 内联配置
*/
vite?: InlineConfig;
}
interface AutoImportComponents {
/**
* 自动导入组件
*/
globs?: string[];
/**
* 自动导入组件解析器
*/
resolvers?: Resolver[];
/**
* 自动导入组件清单输出路径,默认输出到 `vite.config.ts` 同级目录的 `auto-import-components.json`
* - `true` 或未指定: 按默认路径输出
* - 传入字符串: 指定输出路径 (支持绝对/相对路径)
* - `false`: 不生成清单文件
*/
output?: string | boolean;
/**
* 生成 WXML 组件 props 类型声明文件。
* - `true`: 输出到 `vite.config.ts` 同级目录的 `typed-components.d.ts`
* - 传入字符串: 自定义输出路径 (支持绝对/相对路径)
* - `false` 或未配置: 不生成类型文件
*/
typedComponents?: boolean | string;
/**
* 生成 VS Code HTML customData 用于模板补全。
* - `true`: 输出到 `vite.config.ts` 同级目录的 `mini-program.html-data.json`
* - 传入字符串: 自定义输出路径 (支持绝对/相对路径)
* - `false` 或未配置: 不生成 customData
*/
htmlCustomData?: boolean | string;
}
type AutoImportComponentsOption = AutoImportComponents | false;
type EnhanceWxmlOptions = ScanWxmlOptions & HandleWxmlOptions;
interface ScanWxmlOptions {
excludeComponent?: (tagName: string) => boolean;
platform?: MpPlatform;
}
interface HandleWxmlOptions {
removeComment?: boolean;
transformEvent?: boolean;
}
interface EnhanceOptions {
/**
* wxml 增强
*/
wxml?: boolean | (Partial<Omit<EnhanceWxmlOptions, 'platform'>>);
/**
* wxs 增强
*/
wxs?: boolean;
/**
* 自动导入小程序组件
*/
autoImportComponents?: AutoImportComponentsOption;
}
interface BuildNpmPackageMeta {
name: string;
entry: InputOption;
}
type JsFormat = 'cjs' | 'esm';
type SharedChunkStrategy = 'hoist' | 'duplicate';
interface ChunksConfig {
/**
* @description 控制跨分包共享代码的输出策略
* - `duplicate`: 默认策略,将共享代码复制到各自的分包中
* - `hoist`: 将共享代码提炼到主包中
* @default 'duplicate'
*/
sharedStrategy?: SharedChunkStrategy;
/**
* @description 是否输出分包优化日志,帮助确认共享模块被复制或回退的位置
* @default true
*/
logOptimization?: boolean;
/**
* @description 强制按分包复制的模块匹配规则。当共享模块的直接导入方命中这些规则时,
* 其「主包」身份会被忽略,继续沿用 duplicate 策略。支持字符串或正则表达式,默认基于 srcRoot 的相对路径匹配。
*/
forceDuplicatePatterns?: (string | RegExp)[];
/**
* @description 当共享模块复制后的冗余体积(字节)超过该阈值时输出警告。设置为 0 或 undefined 则禁用。
* @default 524288 (约 512 KB)
*/
duplicateWarningBytes?: number;
}
interface WeappViteConfig {
/**
* @description 应用入口目录 (app.json 所在的目录)
* 默认 js 模板在根目录 `.`,ts 模板在 `miniprogram` 目录,当然你可以把所有代码放在 `src` 目录下,并设置此选项为 `src`
* @default '.'
*/
srcRoot?: string;
/**
* @description 是否启用自动路由模块 (`weapp-vite/auto-routes`)
* 默认关闭,需要显式启用后才会扫描 `pages/` 目录并生成路由清单。
* @default false
*/
autoRoutes?: boolean;
/**
* @description 插件入口目录 (plugin.json 所在的目录)
* @default undefined
*/
pluginRoot?: string;
/**
* @group json 配置
* 文件引入别名
*/
jsonAlias?: AliasOptions;
/**
*
* @group 构建 npm
*/
npm?: {
/**
* @description 是否开启构建 npm 功能, 默认为 true
* @default true
*/
enable?: boolean;
/**
* @description 是否开启缓存,默认为 true
* @default true
*/
cache?: boolean;
/**
* @description 构建 npm 的配置,可传入 Vite 的库模式配置,让不同的包走不同的配置
*/
buildOptions?: (options: NpmBuildOptions, pkgMeta: BuildNpmPackageMeta) => NpmBuildOptions | undefined;
};
/**
* @group 生成脚手架配置
* weapp-vite generate 相关的配置
*/
generate?: GenerateOptions;
/**
* @group 插件集成
* 传递给内置 [`vite-tsconfig-paths`](https://www.npmjs.com/package/vite-tsconfig-paths) 插件的参数
*/
tsconfigPaths?: PluginOptions;
/**
* @group 分包配置
* 分包是否独立的 rollup 编译上下文
* 默认情况下,当一个分包设置了 independent: true 之后会默认启用
* 可以设置 key: 为 root, value: {independent:true} 来强制启用 独立的 rollup 编译上下文
*/
subPackages?: Record<string, Pick<SubPackage, 'independent' | 'dependencies' | 'inlineConfig'> & {
autoImportComponents?: AutoImportComponentsOption;
/** 分包文件变更时是否强制重新生成共享样式产物,默认启用 */
watchSharedStyles?: boolean;
/**
* 分包共享样式入口,支持传入一个或多个 `wxss`/`css` 文件路径
* - 相对路径默认基于当前分包的 `root`
* - 也可以传入绝对路径或相对 `srcRoot` 的路径
* - 支持传入对象配置 `scope`/`include`/`exclude` 精准控制注入范围
*/
styles?: SubPackageStyleConfigEntry | SubPackageStyleConfigEntry[];
}>;
/**
* 需要被额外包括的资源
* 默认情况下包括大部分的图片资源格式
*/
copy?: CopyOptions;
/**
* @group Web 运行时
* 浏览器端运行时相关配置
*/
web?: WeappWebConfig;
/**
* @description 额外的 wxml 文件
* 把这个方法,扫描到的 `wxml` 添加到额外的 `wxml` 文件列表, **处理** 之后输出到最终的产物中
* @param wxmlFilePath
* @returns boolean
*/
isAdditionalWxml?: (wxmlFilePath: string) => boolean;
/**
* @description 编译目标平台
* @ignore
*/
platform?: MpPlatform;
/**
* @description 生成的 JS 模块格式
* - `cjs`: 输出 CommonJS
* - `esm`: 输出 ESM,需要在微信开发者工具中启用「ES6 转 ES5」
* @default 'cjs'
*/
jsFormat?: JsFormat;
/**
* @description 是否启用基于 `@swc/core` 的 ES5 降级(仅支持 `jsFormat: 'cjs'`)
* @default false
*/
es5?: boolean;
wxml?: EnhanceOptions['wxml'];
/**
* wxs 增强
*/
wxs?: EnhanceOptions['wxs'];
/**
* 自动导入小程序组件
*/
autoImportComponents?: AutoImportComponentsOption;
/**
* @deprecated 请改用顶层的 `wxml`、`wxs` 与 `autoImportComponents`
* 增强配置
*/
enhance?: EnhanceOptions;
debug?: {
watchFiles?: (watchFiles: string[], subPackageMeta?: SubPackageMetaValue) => void;
resolveId?: (id: string, subPackageMeta?: SubPackageMetaValue) => void;
load?: (id: string, subPackageMeta?: SubPackageMetaValue) => void;
inspect?: WrapPluginOptions;
};
/**
* @description 构建 worker 配置
*/
worker?: {
/**
* @description 构建 worker 的入口
*/
entry?: string | string[];
};
/**
* @description 共享代码拆分策略配置
*/
chunks?: ChunksConfig;
}
type UserConfig = UserConfig$1 & {
weapp?: WeappViteConfig;
};
interface ProjectConfig {
miniprogramRoot?: string;
srcMiniprogramRoot?: string;
setting?: {
packNpmManually?: boolean;
packNpmRelationList?: {
packageJsonPath: string;
miniprogramNpmDistDir: string;
}[];
};
}
interface SubPackageMetaValue {
entries: string[];
subPackage: SubPackage;
autoImportComponents?: AutoImportComponentsOption;
styleEntries?: SubPackageStyleEntry[];
watchSharedStyles?: boolean;
}
interface WxmlDep {
tagName: string;
start: number;
end: number;
quote: string | null | undefined;
name: string;
value: string;
attrs: Record<string, string>;
}
interface ScanComponentItem {
start: number;
end: number;
}
type ComponentsMap = Record<string, ScanComponentItem[]>;
interface BaseEntry {
path: string;
jsonPath?: string;
json?: object;
type: 'app' | 'page' | 'component' | (string & {});
}
type Entry = AppEntry | PageEntry | ComponentEntry;
/**
* 应用入口 js + json
*/
interface AppEntry extends BaseEntry {
type: 'app';
themeJsonPath?: string;
themeJson?: Theme;
sitemapJsonPath?: string;
sitemapJson?: Sitemap;
json: App;
jsonPath: string;
}
/**
* 页面入口 js + wxml
*/
interface PageEntry extends BaseEntry {
type: 'page';
templatePath: string;
json?: Page;
}
/**
* 组件入口 js + wxml + json + json.component === true
*/
interface ComponentEntry extends BaseEntry {
type: 'component';
templatePath: string;
json: Component;
jsonPath: string;
}
type EntryJsonFragment = Omit<BaseEntry, 'path' | 'type'>;
interface BuildOptions {
skipNpm?: boolean;
}
interface BuildService {
queue: PQueue;
build: (options?: BuildOptions) => Promise<RolldownOutput | RolldownOutput[] | RolldownWatcher>;
buildIndependentBundle: (root: string, meta: SubPackageMetaValue) => Promise<RolldownOutput>;
getIndependentOutput: (root: string) => RolldownOutput | undefined;
invalidateIndependentOutput: (root: string) => void;
}
interface OutputExtensions {
js: string;
json: string;
wxml: string;
wxss: string;
wxs?: string;
}
interface LoadConfigOptions {
cwd: string;
isDev: boolean;
mode: string;
inlineConfig?: InlineConfig;
configFile?: string;
}
interface LoadConfigResult {
config: InlineConfig;
aliasEntries: ResolvedAlias[];
outputExtensions: OutputExtensions;
packageJson: PackageJson;
relativeSrcRoot: (p: string) => string;
cwd: string;
isDev: boolean;
mode: string;
projectConfig: Record<string, any>;
mpDistRoot: string;
packageJsonPath: string;
platform: MpPlatform;
srcRoot: string;
configFilePath?: string;
currentSubPackageRoot?: string;
weappWeb?: ResolvedWeappWebConfig;
}
interface PackageInfo {
name: string;
version: string | undefined;
rootPath: string;
packageJsonPath: string;
packageJson: PackageJson;
}
interface ConfigService {
options: LoadConfigResult;
outputExtensions: OutputExtensions;
defineEnv: Record<string, any>;
packageManager: DetectResult;
packageInfo: PackageInfo;
setDefineEnv: (key: string, value: any) => void;
load: (options?: Partial<LoadConfigOptions>) => Promise<LoadConfigResult>;
mergeWorkers: (...configs: Partial<InlineConfig>[]) => InlineConfig;
merge: (subPackageMeta?: SubPackageMetaValue, ...configs: Partial<InlineConfig | undefined>[]) => InlineConfig;
mergeWeb: (...configs: Partial<InlineConfig | undefined>[]) => InlineConfig | undefined;
mergeInlineConfig: (...configs: Partial<InlineConfig>[]) => InlineConfig;
readonly defineImportMetaEnv: Record<string, any>;
readonly cwd: string;
readonly isDev: boolean;
readonly mpDistRoot: string;
readonly outDir: string;
readonly inlineConfig: InlineConfig;
readonly weappViteConfig: NonNullable<InlineConfig['weapp']>;
readonly packageJson: PackageJson;
readonly projectConfig: Record<string, any>;
readonly srcRoot: string;
readonly pluginRoot: string | undefined;
readonly absolutePluginRoot: string | undefined;
readonly absolutePluginOutputRoot: string | undefined;
readonly absoluteSrcRoot: string;
readonly mode: string;
readonly aliasEntries: ResolvedAlias[];
readonly platform: MpPlatform;
readonly configFilePath?: string;
readonly weappWebConfig?: ResolvedWeappWebConfig;
relativeCwd: (p: string) => string;
relativeSrcRoot: (p: string) => string;
relativeAbsoluteSrcRoot: (p: string) => string;
relativeOutputPath: (p: string) => string;
readonly currentSubPackageRoot?: string;
}
interface ResolvedWeappWebConfig {
enabled: boolean;
root: string;
srcDir: string;
outDir: string;
pluginOptions: Omit<WeappWebPluginOptions, 'srcDir'> & {
srcDir: string;
};
userConfig?: InlineConfig;
source?: WeappWebConfig;
}
interface JsonResolvableEntry {
json?: any;
jsonPath?: string;
type?: 'app' | 'page' | 'component' | 'plugin';
}
type HashInput = string | Buffer;
declare class FileCache<T extends object> {
cache: LRUCache<string, T>;
mtimeMap: Map<string, number>;
signatureMap: Map<string, string>;
constructor(max?: number);
get(id: string): T | undefined;
set(id: string, content: T): LRUCache<string, T, unknown>;
delete(id: string): boolean;
isInvalidate(id: string, options?: {
content?: HashInput;
}): Promise<boolean>;
}
interface JsonService {
read: (filepath: string) => Promise<any>;
resolve: (entry: JsonResolvableEntry) => string | undefined;
cache: FileCache<any>;
}
interface NpmService {
getDependenciesCacheFilePath: (key?: string) => string;
readonly dependenciesCacheHash: string;
isMiniprogramPackage: (pkg: PackageJson) => boolean;
shouldSkipBuild: (outDir: string, isOutdated: boolean) => Promise<boolean>;
writeDependenciesCache: (root?: string) => Promise<void>;
readDependenciesCache: (root?: string) => Promise<any>;
checkDependenciesCacheOutdate: (root?: string) => Promise<boolean>;
bundleBuild: (args: {
entry: InputOption;
name: string;
options?: NpmBuildOptions;
outDir: string;
}) => Promise<void>;
copyBuild: (args: {
from: string;
to: string;
name: string;
}) => Promise<void>;
buildPackage: (args: {
dep: string;
outDir: string;
options?: NpmBuildOptions;
isDependenciesCacheOutdate: boolean;
}) => Promise<void>;
getPackNpmRelationList: () => {
packageJsonPath: string;
miniprogramNpmDistDir: string;
}[];
build: (options?: NpmBuildOptions) => Promise<void>;
}
interface Token {
start: number;
end: number;
value: string;
}
interface RemovalRange {
start: number;
end: number;
}
interface WxmlToken {
components: ComponentsMap;
deps: WxmlDep[];
removalRanges: RemovalRange[];
commentTokens: Token[];
inlineWxsTokens: Token[];
wxsImportNormalizeTokens: Token[];
removeWxsLangAttrTokens: Token[];
eventTokens: Token[];
code: string;
}
declare function scanWxml(wxml: string | Buffer, options?: ScanWxmlOptions): WxmlToken;
type ScanWxmlResult = ReturnType<typeof scanWxml>;
interface LocalAutoImportMatch {
kind: 'local';
entry: ComponentEntry;
value: ResolvedValue;
}
interface WatcherInstance {
close: () => void | Promise<void>;
}
interface SidecarWatcher {
close: () => void | Promise<void>;
}
interface AutoRoutesCandidateState {
base: string;
files: Set<string>;
hasScript: boolean;
hasTemplate: boolean;
jsonPath?: string;
}
interface RuntimeState {
autoRoutes: {
routes: AutoRoutes;
serialized: string;
moduleCode: string;
typedDefinition: string;
watchFiles: Set<string>;
watchDirs: Set<string>;
dirty: boolean;
initialized: boolean;
candidates: Map<string, AutoRoutesCandidateState>;
needsFullRescan: boolean;
};
autoImport: {
registry: Map<string, LocalAutoImportMatch>;
matcher?: (input: string) => boolean;
matcherKey: string;
};
build: {
queue: PQueue;
npmBuilt: boolean;
independent: {
outputs: Map<string, RolldownOutput>;
};
};
json: {
cache: FileCache<any>;
};
css: {
importerToDependencies: Map<string, Set<string>>;
dependencyToImporters: Map<string, Set<string>>;
};
watcher: {
rollupWatcherMap: Map<string, WatcherInstance>;
sidecarWatcherMap: Map<string, SidecarWatcher>;
};
wxml: {
depsMap: Map<string, Set<string>>;
tokenMap: Map<string, ScanWxmlResult>;
componentsMap: Map<string, ComponentsMap>;
cache: FileCache<ScanWxmlResult>;
emittedCode: Map<string, string>;
};
scan: {
subPackageMap: Map<string, SubPackageMetaValue>;
independentSubPackageMap: Map<string, SubPackageMetaValue>;
appEntry?: AppEntry;
pluginJson?: Plugin;
pluginJsonPath?: string;
isDirty: boolean;
independentDirtyRoots: Set<string>;
};
config: {
packageInfo: PackageInfo;
defineEnv: Record<string, any>;
packageManager: DetectResult;
options: LoadConfigResult;
};
}
interface ScanService {
appEntry?: AppEntry;
pluginJson?: Plugin;
pluginJsonPath?: string;
subPackageMap: Map<string, SubPackageMetaValue>;
independentSubPackageMap: Map<string, SubPackageMetaValue>;
loadAppEntry: () => Promise<AppEntry>;
loadSubPackages: () => SubPackageMetaValue[];
isMainPackageFileName: (fileName: string) => boolean;
readonly workersOptions: App['workers'] | undefined;
readonly workersDir: string | undefined;
markDirty: () => void;
markIndependentDirty: (root: string) => void;
drainIndependentDirtyRoots: () => string[];
}
interface WatcherService {
rollupWatcherMap: Map<string, WatcherInstance>;
sidecarWatcherMap: Map<string, SidecarWatcher>;
getRollupWatcher: (root?: string) => WatcherInstance | undefined;
setRollupWatcher: (watcher: WatcherInstance, root?: string) => void;
close: (root?: string) => void;
closeAll: () => void;
}
interface WebService {
readonly devServer?: ViteDevServer;
isEnabled: () => boolean;
startDevServer: () => Promise<ViteDevServer | undefined>;
build: () => Promise<Awaited<ReturnType<typeof build>> | undefined>;
close: () => Promise<void>;
}
interface WxmlService {
depsMap: Map<string, Set<string>>;
tokenMap: Map<string, ScanWxmlResult>;
wxmlComponentsMap: Map<string, ComponentsMap>;
addDeps: (filepath: string, deps?: string[]) => Promise<void>;
getAllDeps: () => Set<string>;
clearAll: () => void;
analyze: (wxml: string) => ScanWxmlResult;
scan: (filepath: string) => Promise<ScanWxmlResult | undefined>;
setWxmlComponentsMap: (absPath: string, components: ComponentsMap) => void;
}
interface ResolverAutoImportMatch {
kind: 'resolver';
value: ResolvedValue;
}
type AutoImportMatch = LocalAutoImportMatch | ResolverAutoImportMatch;
interface AutoImportService {
reset: () => void;
registerPotentialComponent: (filePath: string) => Promise<void>;
removePotentialComponent: (filePath: string) => void;
resolve: (componentName: string, importerBaseName?: string) => AutoImportMatch | undefined;
filter: (id: string, meta?: SubPackageMetaValue) => boolean;
getRegisteredLocalComponents: () => LocalAutoImportMatch[];
awaitManifestWrites: () => Promise<void>;
}
type AutoRoutesFileEvent = ChangeEvent | 'rename';
interface AutoRoutesService {
ensureFresh: () => Promise<void>;
markDirty: () => void;
getSnapshot: () => AutoRoutes;
getReference: () => AutoRoutes;
getModuleCode: () => string;
getWatchFiles: () => Iterable<string>;
getWatchDirectories: () => Iterable<string>;
isRouteFile: (filePath: string) => boolean;
handleFileChange: (filePath: string, event?: AutoRoutesFileEvent) => Promise<void>;
isInitialized: () => boolean;
isEnabled: () => boolean;
}
type BuildTarget = 'app' | 'plugin';
interface CompilerContext {
runtimeState: RuntimeState;
configService: ConfigService;
npmService: NpmService;
wxmlService: WxmlService;
jsonService: JsonService;
watcherService: WatcherService;
webService: WebService;
autoImportService: AutoImportService;
autoRoutesService: AutoRoutesService;
buildService: BuildService;
scanService: ScanService;
currentBuildTarget?: BuildTarget;
}
interface WeappVitePluginApi {
ctx: CompilerContext;
}
type ChangeEvent = 'create' | 'update' | 'delete';
type ReturnSelf<T> = (config: T) => T;
type ConfigFn<T> = T | ((ctx: CompilerContext) => T);
type DefineJsonFn<T> = ReturnSelf<ConfigFn<T>>;
declare const defineAppJson: DefineJsonFn<App>;
declare const definePageJson: DefineJsonFn<Page>;
declare const defineComponentJson: DefineJsonFn<Component>;
declare const defineSitemapJson: DefineJsonFn<Sitemap>;
declare const defineThemeJson: DefineJsonFn<Theme>;
declare module 'vite' {
interface UserConfig {
weapp?: WeappViteConfig;
}
}
declare function defineConfig(config: UserConfig$1): UserConfig$1;
declare function defineConfig(config: Promise<UserConfig$1>): Promise<UserConfig$1>;
declare function defineConfig(config: UserConfigFnObject): UserConfigFnObject;
declare function defineConfig(config: UserConfigExport): UserConfigExport;
export { type AppEntry as $, type Alias as A, type AutoImportComponents as B, type CompilerContext as C, type AutoImportComponentsOption as D, type EnhanceWxmlOptions as E, type ScanWxmlOptions as F, type GenerateExtensionsOptions as G, type HandleWxmlOptions as H, type EnhanceOptions as I, type BuildNpmPackageMeta as J, type JsFormat as K, type LoadConfigOptions as L, type MpPlatform as M, type NpmBuildOptions as N, type SharedChunkStrategy as O, type ChunksConfig as P, type ProjectConfig as Q, type ResolvedAlias as R, type SubPackage as S, type SubPackageMetaValue as T, type UserConfig as U, type WxmlDep as V, type WeappViteConfig as W, type ScanComponentItem as X, type ComponentsMap as Y, type BaseEntry as Z, type Entry as _, defineAppJson as a, type PageEntry as a0, type ComponentEntry as a1, type EntryJsonFragment as a2, type WeappVitePluginApi as a3, type ChangeEvent as a4, definePageJson as b, defineComponentJson as c, defineConfig as d, defineSitemapJson as e, defineThemeJson as f, type AliasOptions as g, type SubPackageStyleScope as h, type SubPackageStyleConfigObject as i, type SubPackageStyleConfigEntry as j, type SubPackageStyleEntry as k, type GenerateDirsOptions as l, type GenerateFilenamesOptions as m, type GenerateFileType as n, type GenerateTemplateContext as o, type GenerateTemplateFileSource as p, type GenerateTemplateInlineSource as q, type GenerateTemplateFactory as r, type GenerateTemplate as s, type GenerateTemplateEntry as t, type GenerateTemplateScope as u, type GenerateTemplatesConfig as v, type GenerateOptions as w, type CopyOptions as x, type CopyGlobs as y, type WeappWebConfig as z };