weapp-vite 6.20.5 → 6.22.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.
package/README.md CHANGED
@@ -32,6 +32,7 @@
32
32
  - 🧩 **实验性 uni-app 组件库兼容**:通过显式依赖白名单与 `WotUiResolver()` 在微信小程序和 Web 中使用 Wot UI Vue SFC
33
33
  - 🧰 **IDE 命令增强**:可直接透传 `weapp-ide-cli` 全量命令(`preview/upload/config/automator` 等)
34
34
  - 🧪 **真实产物单测**:`weapp-vite/test` 提供不启动 CLI 的程序化测试构建入口,可配合 `@mpcore/test` 测试页面和组件
35
+ - 🌍 **内置 i18n**:构建期编译 locale JSON,通过 WXS 翻译模板,并在逻辑层安全切换已构建语言
35
36
 
36
37
  ## 快速开始
37
38
 
@@ -122,6 +123,25 @@ function handleClick() {
122
123
 
123
124
  📚 **完整文档**: [Vue 支持文档](./test/vue/README.md)
124
125
 
126
+ ### 一方维护的 i18n
127
+
128
+ ```ts
129
+ import { defineConfig } from 'weapp-vite/config'
130
+
131
+ export default defineConfig({
132
+ weapp: {
133
+ i18n: {
134
+ defaultLocale: 'zh-CN',
135
+ fallbackLocale: 'en-US',
136
+ },
137
+ },
138
+ })
139
+ ```
140
+
141
+ 默认扫描 `src/**/i18n/*.json`。Native Component 和使用 Component 构造的 Page 通过 `behaviors: [i18n.behavior]` 接入;传统 `Page({...})` 使用 `i18n.page(options)` 适配生命周期。Vue/Wevu 使用 `defineOptions({ behaviors: [i18n.behavior] })`。模板中的 `t('key', params)` 会在构建时改写为 WXS 调用;逻辑层从 `weapp-vite/i18n` 导入构建实例,并通过 `i18n.global` 访问翻译和 locale。
142
+
143
+ 底层运行时与 catalog 编译器由独立包 `@weapp-vite/i18n` 提供,也可以在完全不使用 Vite 的原生微信小程序中安装。v1 只支持 `{name}` / `{user.name}` 占位符,不自动持久化语言,也不包含 ICU、复数和日期/数字格式化。完整配置见 [i18n 配置](https://vite.icebreaker.top/config/i18n)。
144
+
125
145
  - 配置智能提示文档:[docs/volar.md](./docs/volar.md)
126
146
  - defineConfig 重载说明:[docs/define-config-overloads.md](./docs/define-config-overloads.md)
127
147
  - Vite 插件识别 weapp-vite 宿主:https://vite.icebreaker.top/guide/vite-plugin-host
@@ -158,6 +178,7 @@ function handleClick() {
158
178
  - `ai-workflows.md`
159
179
  - `project-structure.md`
160
180
  - `weapp-config.md`
181
+ - `i18n.md`
161
182
  - `uni-app-component-libraries.md`
162
183
  - `wevu-authoring.md`
163
184
  - `vue-sfc.md`
@@ -1,4 +1,4 @@
1
- import { n as getCompilerContext, v as getRouteRuntimeGlobalKeys } from "./createContext-Ryo4nfbU.mjs";
1
+ import { n as getCompilerContext, v as getRouteRuntimeGlobalKeys } from "./createContext-PBWMhrli.mjs";
2
2
  //#region src/auto-routes.ts
3
3
  const ROUTE_RUNTIME_OVERRIDE_KEY = Symbol.for("weapp-vite.route-runtime");
4
4
  function createGetter(resolver) {
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { A as isPathInside, C as findPreloadRuleKey, D as createCjsConfigLoadError, E as parseCommentJson, O as getDefaultIdeProjectRoot, S as collectPreloadPages, T as loadViteConfigFile, _ as resolveHmrProfileJsonPath, a as formatBytes, b as checkRuntime, d as getBackendForCapability, f as resolveBackendExecution, g as SHARED_CHUNK_VIRTUAL_PREFIX, h as createSharedBuildConfig, k as shouldPassPlatformArgToIdeOpen, m as syncManagedTsconfigBootstrapFiles, p as syncProjectSupportFiles, t as createCompilerContext, w as suggestPreloadRules, x as getProjectConfigFileName, y as resolveWeappConfigFile } from "./createContext-Ryo4nfbU.mjs";
1
+ import { A as shouldPassPlatformArgToIdeOpen, C as findPreloadRuleKey, D as parseCommentJson, E as loadViteConfigFile, O as createCjsConfigLoadError, S as collectPreloadPages, T as suggestPreloadRules, _ as resolveHmrProfileJsonPath, a as formatBytes, b as checkRuntime, d as getBackendForCapability, f as resolveBackendExecution, g as SHARED_CHUNK_VIRTUAL_PREFIX, h as createSharedBuildConfig, j as isPathInside, k as getDefaultIdeProjectRoot, m as syncManagedTsconfigBootstrapFiles, p as syncProjectSupportFiles, t as createCompilerContext, w as resolvePreloadPackageIdentifier, x as getProjectConfigFileName, y as resolveWeappConfigFile } from "./createContext-PBWMhrli.mjs";
2
2
  import { r as logger_default, t as colors } from "./logger-mt4mSTqV.mjs";
3
- import { h as VERSION, i as findJsEntry, o as findTemplateEntry, s as findVueEntry } from "./file-CWbsTVPm.mjs";
3
+ import { h as VERSION, i as findJsEntry, o as findTemplateEntry, s as findVueEntry } from "./file-D0n-Q1ra.mjs";
4
4
  import { c as startWeappViteMcpServer, l as detectAiDevelopmentEnvironment, s as resolveWeappMcpConfig } from "./mcp-BG6TliEg.mjs";
5
5
  import { createRequire } from "node:module";
6
6
  import fs from "node:fs";
@@ -1070,7 +1070,83 @@ async function analyzeHmrProfile(options) {
1070
1070
  };
1071
1071
  }
1072
1072
  //#endregion
1073
- //#region src/analyze/preload.ts
1073
+ //#region src/analyze/preload/budget.ts
1074
+ const PRELOAD_LIMIT_BYTES = 2097152;
1075
+ function createPackageSizeMap$1(result) {
1076
+ return new Map((result?.packages ?? []).map((pkg) => [pkg.id, pkg.files.reduce((total, file) => total + (file.size ?? 0), 0)]));
1077
+ }
1078
+ function getConfiguredPackages(rule, appJson) {
1079
+ if (!rule || typeof rule !== "object" || !("packages" in rule)) return [];
1080
+ const packages = rule.packages;
1081
+ if (!Array.isArray(packages)) return [];
1082
+ return packages.flatMap((item) => typeof item === "string" ? [resolvePreloadPackageIdentifier(item, appJson)] : []).filter((item) => Boolean(item));
1083
+ }
1084
+ function createPreloadBudgets(appJson, result, configuredRules, packageAnalysis) {
1085
+ const packageSizes = createPackageSizeMap$1(packageAnalysis);
1086
+ const bySourcePackage = /* @__PURE__ */ new Map();
1087
+ const ensureSourcePackage = (page) => {
1088
+ const sourcePackage = page.packageRoot ?? "__main__";
1089
+ let entry = bySourcePackage.get(sourcePackage);
1090
+ if (!entry) {
1091
+ entry = {
1092
+ sourceType: page.packageRoot ? page.independent ? "independent" : "subpackage" : "main",
1093
+ targets: /* @__PURE__ */ new Map()
1094
+ };
1095
+ bySourcePackage.set(sourcePackage, entry);
1096
+ }
1097
+ return entry;
1098
+ };
1099
+ for (const page of result.pages) {
1100
+ const configuredKey = findPreloadRuleKey(page.route, configuredRules);
1101
+ if (configuredKey === void 0) continue;
1102
+ const entry = ensureSourcePackage(page);
1103
+ for (const packageRoot of getConfiguredPackages(configuredRules[configuredKey], appJson)) {
1104
+ const target = entry.targets.get(packageRoot) ?? {
1105
+ configured: false,
1106
+ suggested: false
1107
+ };
1108
+ target.configured = true;
1109
+ entry.targets.set(packageRoot, target);
1110
+ }
1111
+ }
1112
+ const pageByRoute = new Map(result.pages.map((page) => [page.route, page]));
1113
+ for (const suggestion of result.suggestions) {
1114
+ const page = pageByRoute.get(suggestion.page);
1115
+ if (!page) continue;
1116
+ const entry = ensureSourcePackage(page);
1117
+ const target = entry.targets.get(suggestion.packageRoot) ?? {
1118
+ configured: false,
1119
+ suggested: false
1120
+ };
1121
+ target.suggested = true;
1122
+ entry.targets.set(suggestion.packageRoot, target);
1123
+ }
1124
+ return [...bySourcePackage.entries()].map(([sourcePackage, entry]) => {
1125
+ const targets = [...entry.targets.entries()].map(([packageRoot, state]) => {
1126
+ const packageId = packageRoot === "__APP__" ? "__main__" : packageRoot;
1127
+ return {
1128
+ packageRoot,
1129
+ bytes: packageSizes.get(packageId),
1130
+ ...state
1131
+ };
1132
+ }).sort((left, right) => left.packageRoot.localeCompare(right.packageRoot));
1133
+ const unknownPackages = targets.filter((target) => target.bytes === void 0).map((target) => target.packageRoot);
1134
+ const estimatedBytes = targets.reduce((total, target) => total + (target.bytes ?? 0), 0);
1135
+ const status = estimatedBytes > PRELOAD_LIMIT_BYTES ? "exceeded" : unknownPackages.length > 0 ? "unknown" : "ok";
1136
+ return {
1137
+ sourcePackage,
1138
+ sourceType: entry.sourceType,
1139
+ limitBytes: PRELOAD_LIMIT_BYTES,
1140
+ estimatedBytes,
1141
+ remainingBytes: unknownPackages.length === 0 ? Math.max(0, PRELOAD_LIMIT_BYTES - estimatedBytes) : void 0,
1142
+ status,
1143
+ targets,
1144
+ unknownPackages
1145
+ };
1146
+ }).sort((left, right) => left.sourcePackage.localeCompare(right.sourcePackage));
1147
+ }
1148
+ //#endregion
1149
+ //#region src/analyze/preload/index.ts
1074
1150
  async function readFileIfExists(filePath) {
1075
1151
  if (!filePath) return;
1076
1152
  try {
@@ -1110,7 +1186,7 @@ async function collectPageSources(ctx, route) {
1110
1186
  script
1111
1187
  };
1112
1188
  }
1113
- function aggregateSuggestions(result, configuredRules) {
1189
+ function aggregateSuggestions(result, configuredRules, appJson) {
1114
1190
  const byPage = /* @__PURE__ */ new Map();
1115
1191
  for (const suggestion of result.suggestions) {
1116
1192
  const current = byPage.get(suggestion.page) ?? {
@@ -1128,7 +1204,7 @@ function aggregateSuggestions(result, configuredRules) {
1128
1204
  const configuredKey = findPreloadRuleKey(suggestion.page, configuredRules);
1129
1205
  const existingRule = configuredKey === void 0 ? void 0 : configuredRules[configuredKey];
1130
1206
  const existingPackages = existingRule && typeof existingRule === "object" && "packages" in existingRule ? existingRule.packages : void 0;
1131
- if (Array.isArray(existingPackages) && existingPackages.includes(suggestion.packageRoot)) current.alreadyConfigured.push(suggestion.packageRoot);
1207
+ if ((Array.isArray(existingPackages) ? existingPackages.flatMap((item) => typeof item === "string" ? [resolvePreloadPackageIdentifier(item, appJson)] : []) : []).includes(suggestion.packageRoot)) current.alreadyConfigured.push(suggestion.packageRoot);
1132
1208
  byPage.set(suggestion.page, current);
1133
1209
  }
1134
1210
  return [...byPage.values()].map((suggestion) => ({
@@ -1138,7 +1214,7 @@ function aggregateSuggestions(result, configuredRules) {
1138
1214
  evidence: suggestion.evidence.sort((left, right) => left.target.localeCompare(right.target))
1139
1215
  }));
1140
1216
  }
1141
- async function analyzePreloadRules(ctx, now = /* @__PURE__ */ new Date()) {
1217
+ async function analyzePreloadRules(ctx, options = {}) {
1142
1218
  const appJson = (await ctx.scanService.loadAppEntry()).json;
1143
1219
  const pages = collectPreloadPages(appJson);
1144
1220
  const pageSources = /* @__PURE__ */ new Map();
@@ -1149,15 +1225,17 @@ async function analyzePreloadRules(ctx, now = /* @__PURE__ */ new Date()) {
1149
1225
  return {
1150
1226
  runtime: "mini",
1151
1227
  kind: "preload",
1152
- generatedAt: now.toISOString(),
1228
+ generatedAt: (options.now ?? /* @__PURE__ */ new Date()).toISOString(),
1153
1229
  platform: ctx.configService.platform,
1154
1230
  pages: pages.map((page) => page.route),
1155
1231
  configuredRules,
1156
- suggestions: aggregateSuggestions(suggestions, configuredRules),
1232
+ suggestions: aggregateSuggestions(suggestions, configuredRules, appJson),
1233
+ budgets: createPreloadBudgets(appJson, suggestions, configuredRules, options.packageAnalysis),
1157
1234
  uncoveredPages: suggestions.uncovered,
1158
1235
  limitations: [
1159
1236
  "仅分析静态路由字面量;动态路由、后端配置和运行时守卫不会被推断。",
1160
- "建议使用分包 root 作为 packages 值,正式启用前仍需结合业务访问频率和 2 MB 预下载额度复核。",
1237
+ "建议使用分包 root 作为 packages 值;预算按触发页所属包聚合,未知体积目标仍需人工复核。",
1238
+ "静态跳转只能证明可达性,不能代表真实访问频率,正式启用前仍需结合业务数据确认。",
1161
1239
  "该命令只提供可审计建议,不会自动修改源码或覆盖手写的 app.json.preloadRule。"
1162
1240
  ]
1163
1241
  };
@@ -2563,6 +2641,23 @@ async function startAnalyzeDashboard(result, options) {
2563
2641
  await waitPromise;
2564
2642
  }
2565
2643
  //#endregion
2644
+ //#region src/cli/processCleanup.ts
2645
+ function isSassEmbeddedChild(handle) {
2646
+ if (!handle || typeof handle !== "object") return false;
2647
+ const child = handle;
2648
+ const spawnfile = typeof child.spawnfile === "string" ? child.spawnfile : "";
2649
+ const spawnargs = Array.isArray(child.spawnargs) ? child.spawnargs : [];
2650
+ return Boolean("kill" in handle && "spawnfile" in handle && (spawnfile.includes("sass-embedded") || spawnfile.includes("dart-sass") && spawnargs.includes("--embedded")));
2651
+ }
2652
+ function terminateStaleSassEmbeddedProcess() {
2653
+ const getHandles = process._getActiveHandles;
2654
+ const handles = typeof getHandles === "function" ? getHandles() : void 0;
2655
+ if (!Array.isArray(handles)) return;
2656
+ for (const handle of handles) if (isSassEmbeddedChild(handle)) try {
2657
+ handle.kill();
2658
+ } catch {}
2659
+ }
2660
+ //#endregion
2566
2661
  //#region src/cli/commands/analyze.ts
2567
2662
  function normalizeDisplayPath(value) {
2568
2663
  return value || ".";
@@ -2687,6 +2782,15 @@ function printPreloadAnalysisSummary(result) {
2687
2782
  for (const evidence of suggestion.evidence.slice(0, 5)) logger_default.info(` - ${evidence.source}:${evidence.target}`);
2688
2783
  }
2689
2784
  if (result.uncoveredPages.length > 0) logger_default.warn(`- 未找到可扫描源码的页面:${result.uncoveredPages.join("、")}`);
2785
+ if (result.budgets.length > 0) {
2786
+ logger_default.info("预下载额度:");
2787
+ for (const budget of result.budgets) {
2788
+ const size = `${formatAnalyzeBytes(budget.estimatedBytes)} / ${formatAnalyzeBytes(budget.limitBytes)}`;
2789
+ const unknown = budget.unknownPackages.length > 0 ? `,未知:${budget.unknownPackages.join("、")}` : "";
2790
+ const status = budget.status === "exceeded" ? "超限" : budget.status === "unknown" ? "待确认" : "正常";
2791
+ logger_default.info(`- ${budget.sourcePackage}:${size},${status}${unknown}`);
2792
+ }
2793
+ }
2690
2794
  for (const limitation of result.limitations) logger_default.warn(`- 限制:${limitation}`);
2691
2795
  }
2692
2796
  async function writeAnalyzeResult(result, outputOption, configService, format = "json", previousResult) {
@@ -2809,7 +2913,7 @@ function printHmrProfileAnalysisSummary(result, configService) {
2809
2913
  }
2810
2914
  }
2811
2915
  function registerAnalyzeCommand(cli) {
2812
- cli.command("analyze [root]", "analyze 两端包体与源码映射").option("--hmr-profile [file]", `[string | boolean] 分析 HMR JSONL profile,省略值时优先读取配置,否则回退到默认路径`).option("--json", `[boolean] 输出 JSON 结果`).option("--markdown", `[boolean] 输出 Markdown 报告`).option("--report <type>", `[string] 输出指定报告类型(pr)`).option("--budget-check", `[boolean] 检查 analyze 预算,超过预算时返回非 0 退出码`).option("--preload", `[boolean] 分析静态页面跳转并输出 preloadRule 建议`).option("--output <file>", `[string] 将分析结果写入指定文件(JSON 或 Markdown)`).option("-p, --platform <platform>", `[string] target platform (weapp | web)`).option("--project-config <path>", `[string] project config path (miniprogram only)`).action(async (root, options) => {
2916
+ cli.command("analyze [root]", "analyze 两端包体与源码映射").option("--hmr-profile [file]", `[string | boolean] 分析 HMR JSONL profile,省略值时优先读取配置,否则回退到默认路径`).option("--json", `[boolean] 输出 JSON 结果`).option("--markdown", `[boolean] 输出 Markdown 报告`).option("--report <type>", `[string] 输出指定报告类型(pr)`).option("--budget-check", `[boolean] 检查 analyze 预算,超过预算时返回非 0 退出码`).option("--preload", `[boolean] 分析静态页面跳转、实际分包体积和 preloadRule 额度`).option("--output <file>", `[string] 将分析结果写入指定文件(JSON 或 Markdown)`).option("-p, --platform <platform>", `[string] target platform (weapp | web)`).option("--project-config <path>", `[string] project config path (miniprogram only)`).action(async (root, options) => {
2813
2917
  filterDuplicateOptions(options);
2814
2918
  const configFile = resolveConfigFile(options);
2815
2919
  const outputJson = coerceBooleanOption(options.json);
@@ -2820,8 +2924,9 @@ function registerAnalyzeCommand(cli) {
2820
2924
  const budgetCheck = coerceBooleanOption(options.budgetCheck);
2821
2925
  const targets = resolveRuntimeTargets(options);
2822
2926
  const inlineConfig = createInlineConfig(targets);
2927
+ let ctx;
2823
2928
  try {
2824
- const ctx = await createCompilerContext({
2929
+ ctx = await createCompilerContext({
2825
2930
  cwd: root,
2826
2931
  mode: options.mode ?? "production",
2827
2932
  configFile,
@@ -2851,7 +2956,8 @@ function registerAnalyzeCommand(cli) {
2851
2956
  }
2852
2957
  if (coerceBooleanOption(options.preload)) {
2853
2958
  if (targets.kind !== "miniprogram" || ctx.configService.platform !== "weapp") throw new Error("preloadRule 分析目前仅支持微信小程序平台。");
2854
- const preloadResult = await analyzePreloadRules(ctx);
2959
+ const packageAnalysis = await analyzeSubpackages(ctx);
2960
+ const preloadResult = await analyzePreloadRules(ctx, { packageAnalysis });
2855
2961
  const writtenPath = await writeAnalyzeResult(preloadResult, outputOption, ctx.configService);
2856
2962
  if (outputJson && !writtenPath) process.stdout.write(`${JSON.stringify(preloadResult, null, 2)}\n`);
2857
2963
  if (!outputJson && !writtenPath) printPreloadAnalysisSummary(preloadResult);
@@ -2894,6 +3000,11 @@ function registerAnalyzeCommand(cli) {
2894
3000
  } catch (error) {
2895
3001
  logger_default.error(error);
2896
3002
  process.exitCode = 1;
3003
+ } finally {
3004
+ if (ctx) {
3005
+ for (const backend of [...targets.entries].reverse()) if (backend.descriptor.capabilities.analyze) await backend.driver?.close?.(ctx);
3006
+ }
3007
+ terminateStaleSassEmbeddedProcess();
2897
3008
  }
2898
3009
  });
2899
3010
  }
@@ -2995,17 +3106,6 @@ function setCommandNodeEnv(nodeEnv) {
2995
3106
  }
2996
3107
  //#endregion
2997
3108
  //#region src/cli/commands/build.ts
2998
- function isSassEmbeddedChild(handle) {
2999
- return Boolean(handle && typeof handle === "object" && "kill" in handle && "spawnfile" in handle && typeof handle.spawnfile === "string" && handle.spawnfile?.includes("sass-embedded"));
3000
- }
3001
- function terminateStaleSassEmbeddedProcess() {
3002
- const getHandles = process._getActiveHandles;
3003
- const handles = typeof getHandles === "function" ? getHandles() : void 0;
3004
- if (!Array.isArray(handles)) return;
3005
- for (const handle of handles) if (isSassEmbeddedChild(handle)) try {
3006
- handle.kill();
3007
- } catch {}
3008
- }
3009
3109
  function emitDashboardEvents$1(handle, events) {
3010
3110
  handle?.emitRuntimeEvents(events);
3011
3111
  }
@@ -4845,7 +4945,7 @@ function resolveRunnableHotkeyDefinition(input) {
4845
4945
  }
4846
4946
  //#endregion
4847
4947
  //#region package.json
4848
- var version = "6.20.5";
4948
+ var version = "6.22.0";
4849
4949
  //#endregion
4850
4950
  //#region src/cli/devHotkeys/format.ts
4851
4951
  const FULLWIDTH_ASCII_START = 65281;
@@ -0,0 +1,2 @@
1
+ import { WevuCompatibilityDiagnostic, WevuCompatibilityEntry, WevuCompatibilityLevel, WevuCompatibilitySurface, WevuCompatibilityUpstream, findWevuCompatibilityEntry, wevuCompatibilityCatalog } from "@weapp-vite/eslint";
2
+ export { type WevuCompatibilityDiagnostic, type WevuCompatibilityEntry, type WevuCompatibilityLevel, type WevuCompatibilitySurface, type WevuCompatibilityUpstream, findWevuCompatibilityEntry, wevuCompatibilityCatalog };
@@ -0,0 +1,2 @@
1
+ import { findWevuCompatibilityEntry, wevuCompatibilityCatalog } from "@weapp-vite/eslint";
2
+ export { findWevuCompatibilityEntry, wevuCompatibilityCatalog };
@@ -1,5 +1,6 @@
1
1
  import { d as ResolvedValue, f as Resolver } from "./index-CaXAtb9e.mjs";
2
2
  import { t as AutoRoutes } from "./routes-C7fCmf92.mjs";
3
+ import { t as WeappI18nConfig } from "./types-CgZn5X6j.mjs";
3
4
  import { MpPlatform, OutputExtensions } from "@weapp-core/shared";
4
5
  import { WeappAstConfig } from "@weapp-vite/ast";
5
6
  import "@weapp-vite/ast/operations/onPageScroll";
@@ -151,29 +152,36 @@ interface SubPackage {
151
152
  */
152
153
  inlineConfig?: Partial<InlineConfig>;
153
154
  }
154
- type SubPackageStyleScope = 'all' | 'pages' | 'components';
155
- interface SubPackageStyleConfigObject {
156
- /** 样式文件路径,可以是相对分包 root、相对 `srcRoot` 或绝对路径 */
155
+ type StyleScope = 'all' | 'pages' | 'components';
156
+ interface StyleConfigObject {
157
+ /** 样式文件路径,可以是相对当前包 root、相对 `srcRoot` 或绝对路径 */
157
158
  source: string;
158
159
  /**
159
160
  * @description 作用范围快捷配置
160
161
  */
161
- scope?: SubPackageStyleScope;
162
- /** 自定义包含路径,支持传入单个 glob 或数组,默认覆盖分包内所有文件 */
162
+ scope?: StyleScope;
163
+ /** 自定义包含路径,支持传入单个 glob 或数组;主包默认不包含 app,需显式匹配 `app.vue` 等应用入口 */
163
164
  include?: string | string[];
164
165
  /** 自定义排除路径,支持传入单个 glob 或数组 */
165
166
  exclude?: string | string[];
167
+ /** 是否自动向命中的页面或组件样式注入 `@import`,关闭后只生成独立样式文件 */
168
+ inject?: boolean;
166
169
  }
167
- type SubPackageStyleConfigEntry = string | SubPackageStyleConfigObject;
168
- interface SubPackageStyleEntry {
170
+ type StyleConfigEntry = string | StyleConfigObject;
171
+ interface StyleEntry {
169
172
  source: string;
170
173
  absolutePath: string;
171
174
  outputRelativePath: string;
172
175
  inputExtension: string;
173
- scope: SubPackageStyleScope;
176
+ scope: StyleScope;
174
177
  include: string[];
175
178
  exclude: string[];
179
+ inject?: boolean;
176
180
  }
181
+ type SubPackageStyleScope = StyleScope;
182
+ type SubPackageStyleConfigObject = StyleConfigObject;
183
+ type SubPackageStyleConfigEntry = StyleConfigEntry;
184
+ type SubPackageStyleEntry = StyleEntry;
177
185
  type GenerateExtensionsOptions = Partial<{
178
186
  js: 'js' | 'ts' | (string & {});
179
187
  json: 'js' | 'ts' | 'json' | (string & {});
@@ -342,6 +350,10 @@ interface ChunksConfig {
342
350
  sharedMode?: SharedChunkMode;
343
351
  sharedOverrides?: SharedChunkOverride[];
344
352
  sharedPathRoot?: string;
353
+ /**
354
+ * @description 按 srcRoot 相对路径保留匹配源码模块的独立输出边界
355
+ */
356
+ preserveModules?: (string | RegExp)[];
345
357
  dynamicImports?: SharedChunkDynamicImports;
346
358
  logOptimization?: boolean;
347
359
  forceDuplicatePatterns?: (string | RegExp)[];
@@ -562,7 +574,7 @@ interface WeappSubPackageConfig {
562
574
  inlineConfig?: Partial<InlineConfig>;
563
575
  autoImportComponents?: AutoImportComponentsOption;
564
576
  watchSharedStyles?: boolean;
565
- styles?: SubPackageStyleConfigEntry | SubPackageStyleConfigEntry[];
577
+ styles?: StyleConfigEntry | StyleConfigEntry[];
566
578
  }
567
579
  /**
568
580
  * @description HMR 配置
@@ -678,7 +690,7 @@ interface SubPackageMetaValue {
678
690
  entries: string[];
679
691
  subPackage: SubPackage;
680
692
  autoImportComponents?: AutoImportComponentsOption;
681
- styleEntries?: SubPackageStyleEntry[];
693
+ styleEntries?: StyleEntry[];
682
694
  watchSharedStyles?: boolean;
683
695
  }
684
696
  /**
@@ -793,6 +805,10 @@ interface WeappViteConfig {
793
805
  * - `object`: 启用自动路由并允许细粒度控制
794
806
  */
795
807
  autoRoutes?: boolean | WeappAutoRoutesConfig;
808
+ /**
809
+ * 小程序 i18n 构建与运行时配置。
810
+ */
811
+ i18n?: WeappI18nConfig;
796
812
  /**
797
813
  * 插件入口目录(`plugin.json` 所在目录)。
798
814
  */
@@ -821,6 +837,10 @@ interface WeappViteConfig {
821
837
  npm?: WeappNpmConfig;
822
838
  generate?: GenerateOptions;
823
839
  tsconfigPaths?: boolean | PluginOptions;
840
+ /**
841
+ * 主包共享样式入口。生成独立样式文件,并按配置注入主包与普通分包页面或组件。
842
+ */
843
+ styles?: StyleConfigEntry | StyleConfigEntry[];
824
844
  subPackages?: Record<string, WeappSubPackageConfig>;
825
845
  copy?: CopyOptions;
826
846
  web?: WeappWebConfig;
@@ -1571,6 +1591,11 @@ interface WxmlToken {
1571
1591
  removalRanges: RemovalRange[];
1572
1592
  commentTokens: Token[];
1573
1593
  inlineWxsTokens: Token[];
1594
+ scriptModules?: Array<{
1595
+ attrs: Record<string, string>;
1596
+ tagName: string;
1597
+ }>;
1598
+ templateTokens?: Token[];
1574
1599
  wxsImportNormalizeTokens: Token[];
1575
1600
  removeWxsLangAttrTokens: Token[];
1576
1601
  templateImportNormalizeTokens: Token[];
@@ -1642,6 +1667,7 @@ interface RuntimeState {
1642
1667
  npmBuilt: boolean;
1643
1668
  independent: {
1644
1669
  outputs: Map<string, RolldownOutput>;
1670
+ pendingOutputs: Promise<RolldownOutput>[];
1645
1671
  };
1646
1672
  output: {
1647
1673
  emittedSource: Map<string, string>;
@@ -1826,6 +1852,7 @@ interface RuntimeState {
1826
1852
  emittedCode: Map<string, string>;
1827
1853
  };
1828
1854
  scan: {
1855
+ mainPackageStyleEntries?: StyleEntry[];
1829
1856
  subPackageMap: Map<string, SubPackageMetaValue>;
1830
1857
  independentSubPackageMap: Map<string, SubPackageMetaValue>;
1831
1858
  warnedMessages: Set<string>;
@@ -1853,6 +1880,7 @@ interface ScanService {
1853
1880
  appEntry?: AppEntry;
1854
1881
  pluginJson?: Plugin;
1855
1882
  pluginJsonPath?: string;
1883
+ readonly mainPackageStyleEntries: StyleEntry[] | undefined;
1856
1884
  subPackageMap: Map<string, SubPackageMetaValue>;
1857
1885
  independentSubPackageMap: Map<string, SubPackageMetaValue>;
1858
1886
  loadAppEntry: () => Promise<AppEntry>;
@@ -2042,4 +2070,4 @@ declare module 'vite' {
2042
2070
  */
2043
2071
  declare function defineConfig<T extends UserConfigExport>(config: T): T;
2044
2072
  //#endregion
2045
- export { WeappAnalyzeBudgetConfig as $, WEB_PLATFORM_ALIASES as $n, GenerateFilenamesOptions as $t, Ref as A, SubPackageStyleEntry as An, WeappReactCompilerConfig as At, BindingErrorLike as B, WeappManagedNodeTsconfigConfig as Bn, WeappWevuConfig as Bt, LoadConfigOptions as C, SharedChunkDynamicImports as Cn, WeappInjectWeapiConfig as Ct, MethodDefinitions$1 as D, SubPackage as Dn, WeappNpmConfig as Dt, InlineConfig$1 as E, SharedChunkStrategy as En, WeappMcpConfig as Et, RolldownPlugin as F, WeappLibEntryContext as Fn, WeappSubPackageConfig as Ft, EntryJsonFragment as G, WEAPP_VITE_HOST_NAME as Gn, BuildNpmPackageMeta as Gt, BaseEntry as H, WeappManagedSharedTsconfigConfig as Hn, Alias as Ht, RolldownPluginOption as I, WeappLibFileName as In, WeappUniAppConfig as It, ScanComponentItem as J, createWeappViteHostMeta as Jn, CopyOptions as Jt, PageEntry as K, WeappViteHostMeta as Kn, ChunksConfig as Kt, RolldownWatchOptions as L, WeappLibInternalDtsOptions as Ln, WeappVueConfig as Lt, RolldownBuild as M, WeappLibComponentJson as Mn, WeappRequestRuntimeConfig as Mt, RolldownOptions as N, WeappLibConfig as Nn, WeappRouteRule as Nt, Plugin$1 as O, SubPackageStyleConfigEntry as On, WeappPreloadNetwork as Ot, RolldownOutput$1 as P, WeappLibDtsOptions as Pn, WeappRouteRules as Pt, UserConfig$2 as Q, ResolvedWeappViteTarget as Qn, GenerateFileType as Qt, RolldownWatcher$1 as R, WeappLibVueTscOptions as Rn, WeappVueTemplateConfig as Rt, CompilerContext as S, ResolvedAlias as Sn, WeappInjectRequestGlobalsTarget as St, ConfigEnv$1 as T, SharedChunkOverride as Tn, WeappInjectWebRuntimeGlobalsTarget as Tt, ComponentEntry as U, WeappManagedTypeScriptConfig as Un, AliasOptions as Ut, AppEntry as V, WeappManagedServerTsconfigConfig as Vn, WeappWorkerConfig as Vt, Entry as W, WeappWebConfig as Wn, AlipayNpmMode as Wt, ProjectConfig as X, resolveWeappViteHostMeta as Xn, GenerateDirsOptions as Xt, WxmlDep as Y, isWeappViteHost as Yn, DeprecatedInlineDynamicImports as Yt, SubPackageMetaValue as Z, ResolveWeappViteTargetOptions as Zn, GenerateExtensionsOptions as Zt, definePageJson as _, NpmDependencyPattern as _n, WeappAutoRoutesIncludePattern as _t, UserConfigFnNoEnvPlain as a, GenerateTemplateFileSource as an, WebPlatform as ar, WeappViteConfig as at, ChangeEvent as b, NpmStrategy as bn, WeappHmrConfig as bt, UserConfigFnPromise as c, GenerateTemplatesConfig as cn, isWebPlatform as cr, EnhanceOptions as ct, Component$1 as d, JsonMergeContext as dn, MultiPlatformConfig as dt, GenerateOptions as en, WeappVitePlatform as er, WeappAnalyzeConfig as et, Page$1 as f, JsonMergeFunction as fn, ScanWxmlOptions as ft, defineComponentJson as g, NpmBuildOptions as gn, WeappAutoRoutesInclude as gt, defineAppJson as h, MpPlatform$1 as hn, WeappAutoRoutesConfig as ht, UserConfigFnNoEnv as i, GenerateTemplateFactory as in, WeappViteTargetKind as ir, WeappForwardConsoleLogLevel as it, ResolvedConfig as j, SubPackageStyleScope as jn, WeappReactConfig as jt, PluginOption as k, SubPackageStyleConfigObject as kn, WeappPreloadRule as kt, defineConfig as l, JsFormat as ln, resolveWeappViteTarget as lr, EnhanceWxmlOptions as lt, Theme$1 as m, JsonMergeStrategy as mn, WeappAppPreludeMode as mt, UserConfigExport as n, GenerateTemplateContext as nn, WeappViteTargetDescriptor as nr, WeappDebugConfig as nt, UserConfigFnObject as o, GenerateTemplateInlineSource as on, getSupportedWeappVitePlatforms as or, AutoImportComponents as ot, Sitemap$1 as p, JsonMergeStage as pn, WeappAppPreludeConfig as pt, ComponentsMap as q, applyWeappViteHostMeta as qn, CopyGlobs as qt, UserConfigFn as r, GenerateTemplateEntry as rn, WeappViteTargetInput as rr, WeappForwardConsoleConfig as rt, UserConfigFnObjectPlain as s, GenerateTemplateScope as sn, getSupportedWeappViteTargetDescriptors as sr, AutoImportComponentsOption as st, UserConfig$1 as t, GenerateTemplate as tn, WeappViteRuntime as tr, WeappAnalyzeHistoryConfig as tt, App$1 as u, JsonConfig as un, HandleWxmlOptions as ut, defineSitemapJson as v, NpmMainPackageConfig as vn, WeappBuildScopeConfig as vt, ComputedDefinitions$1 as w, SharedChunkMode as wn, WeappInjectWebRuntimeGlobalsConfig as wt, WeappVitePluginApi as x, NpmSubPackageConfig as xn, WeappInjectRequestGlobalsConfig as xt, defineThemeJson as y, NpmPluginPackageConfig as yn, WeappBuildScopeObjectConfig as yt, ViteDevServer$1 as z, WeappManagedAppTsconfigConfig as zn, WeappWebRuntimeConfig as zt };
2073
+ export { WeappAnalyzeBudgetConfig as $, isWeappViteHost as $n, GenerateFilenamesOptions as $t, Ref as A, StyleScope as An, WeappReactCompilerConfig as At, BindingErrorLike as B, WeappLibFileName as Bn, WeappWevuConfig as Bt, LoadConfigOptions as C, SharedChunkDynamicImports as Cn, WeappInjectWeapiConfig as Ct, MethodDefinitions$1 as D, StyleConfigEntry as Dn, WeappNpmConfig as Dt, InlineConfig$1 as E, SharedChunkStrategy as En, WeappMcpConfig as Et, RolldownPlugin as F, SubPackageStyleScope as Fn, WeappSubPackageConfig as Ft, EntryJsonFragment as G, WeappManagedServerTsconfigConfig as Gn, BuildNpmPackageMeta as Gt, BaseEntry as H, WeappLibVueTscOptions as Hn, Alias as Ht, RolldownPluginOption as I, WeappLibComponentJson as In, WeappUniAppConfig as It, ScanComponentItem as J, WeappWebConfig as Jn, CopyOptions as Jt, PageEntry as K, WeappManagedSharedTsconfigConfig as Kn, ChunksConfig as Kt, RolldownWatchOptions as L, WeappLibConfig as Ln, WeappVueConfig as Lt, RolldownBuild as M, SubPackageStyleConfigEntry as Mn, WeappRequestRuntimeConfig as Mt, RolldownOptions as N, SubPackageStyleConfigObject as Nn, WeappRouteRule as Nt, Plugin$1 as O, StyleConfigObject as On, WeappPreloadNetwork as Ot, RolldownOutput$1 as P, SubPackageStyleEntry as Pn, WeappRouteRules as Pt, UserConfig$2 as Q, createWeappViteHostMeta as Qn, GenerateFileType as Qt, RolldownWatcher$1 as R, WeappLibDtsOptions as Rn, WeappVueTemplateConfig as Rt, CompilerContext as S, ResolvedAlias as Sn, WeappInjectRequestGlobalsTarget as St, ConfigEnv$1 as T, SharedChunkOverride as Tn, WeappInjectWebRuntimeGlobalsTarget as Tt, ComponentEntry as U, WeappManagedAppTsconfigConfig as Un, AliasOptions as Ut, AppEntry as V, WeappLibInternalDtsOptions as Vn, WeappWorkerConfig as Vt, Entry as W, WeappManagedNodeTsconfigConfig as Wn, AlipayNpmMode as Wt, ProjectConfig as X, WeappViteHostMeta as Xn, GenerateDirsOptions as Xt, WxmlDep as Y, WEAPP_VITE_HOST_NAME as Yn, DeprecatedInlineDynamicImports as Yt, SubPackageMetaValue as Z, applyWeappViteHostMeta as Zn, GenerateExtensionsOptions as Zt, definePageJson as _, NpmDependencyPattern as _n, WeappAutoRoutesIncludePattern as _t, UserConfigFnNoEnvPlain as a, GenerateTemplateFileSource as an, WeappViteRuntime as ar, WeappViteConfig as at, ChangeEvent as b, NpmStrategy as bn, WeappHmrConfig as bt, UserConfigFnPromise as c, GenerateTemplatesConfig as cn, WeappViteTargetKind as cr, EnhanceOptions as ct, Component$1 as d, JsonMergeContext as dn, getSupportedWeappViteTargetDescriptors as dr, MultiPlatformConfig as dt, GenerateOptions as en, resolveWeappViteHostMeta as er, WeappAnalyzeConfig as et, Page$1 as f, JsonMergeFunction as fn, isWebPlatform as fr, ScanWxmlOptions as ft, defineComponentJson as g, NpmBuildOptions as gn, WeappAutoRoutesInclude as gt, defineAppJson as h, MpPlatform$1 as hn, WeappAutoRoutesConfig as ht, UserConfigFnNoEnv as i, GenerateTemplateFactory as in, WeappVitePlatform as ir, WeappForwardConsoleLogLevel as it, ResolvedConfig as j, SubPackage as jn, WeappReactConfig as jt, PluginOption as k, StyleEntry as kn, WeappPreloadRule as kt, defineConfig as l, JsFormat as ln, WebPlatform as lr, EnhanceWxmlOptions as lt, Theme$1 as m, JsonMergeStrategy as mn, WeappAppPreludeMode as mt, UserConfigExport as n, GenerateTemplateContext as nn, ResolvedWeappViteTarget as nr, WeappDebugConfig as nt, UserConfigFnObject as o, GenerateTemplateInlineSource as on, WeappViteTargetDescriptor as or, AutoImportComponents as ot, Sitemap$1 as p, JsonMergeStage as pn, resolveWeappViteTarget as pr, WeappAppPreludeConfig as pt, ComponentsMap as q, WeappManagedTypeScriptConfig as qn, CopyGlobs as qt, UserConfigFn as r, GenerateTemplateEntry as rn, WEB_PLATFORM_ALIASES as rr, WeappForwardConsoleConfig as rt, UserConfigFnObjectPlain as s, GenerateTemplateScope as sn, WeappViteTargetInput as sr, AutoImportComponentsOption as st, UserConfig$1 as t, GenerateTemplate as tn, ResolveWeappViteTargetOptions as tr, WeappAnalyzeHistoryConfig as tt, App$1 as u, JsonConfig as un, getSupportedWeappVitePlatforms as ur, HandleWxmlOptions as ut, defineSitemapJson as v, NpmMainPackageConfig as vn, WeappBuildScopeConfig as vt, ComputedDefinitions$1 as w, SharedChunkMode as wn, WeappInjectWebRuntimeGlobalsConfig as wt, WeappVitePluginApi as x, NpmSubPackageConfig as xn, WeappInjectRequestGlobalsConfig as xt, defineThemeJson as y, NpmPluginPackageConfig as yn, WeappBuildScopeObjectConfig as yt, ViteDevServer$1 as z, WeappLibEntryContext as zn, WeappWebRuntimeConfig as zt };
package/dist/config.d.mts CHANGED
@@ -1,2 +1,3 @@
1
- import { Gn as WEAPP_VITE_HOST_NAME, Jn as createWeappViteHostMeta, Kn as WeappViteHostMeta, Xn as resolveWeappViteHostMeta, Yn as isWeappViteHost, _ as definePageJson, a as UserConfigFnNoEnvPlain, at as WeappViteConfig, c as UserConfigFnPromise, d as Component, f as Page, g as defineComponentJson, h as defineAppJson, i as UserConfigFnNoEnv, l as defineConfig, m as Theme, n as UserConfigExport, o as UserConfigFnObject, p as Sitemap, qn as applyWeappViteHostMeta, r as UserConfigFn, s as UserConfigFnObjectPlain, t as UserConfig, tr as WeappViteRuntime, u as App, v as defineSitemapJson, y as defineThemeJson } from "./config-B1H1OqnR.mjs";
2
- export { type App, type Component, type Page, type Sitemap, type Theme, UserConfig, UserConfigExport, UserConfigFn, UserConfigFnNoEnv, UserConfigFnNoEnvPlain, UserConfigFnObject, UserConfigFnObjectPlain, UserConfigFnPromise, WEAPP_VITE_HOST_NAME, type WeappViteConfig, WeappViteHostMeta, type WeappViteRuntime, applyWeappViteHostMeta, createWeappViteHostMeta, defineAppJson, defineComponentJson, defineConfig, definePageJson, defineSitemapJson, defineThemeJson, isWeappViteHost, resolveWeappViteHostMeta };
1
+ import { $n as isWeappViteHost, Qn as createWeappViteHostMeta, Xn as WeappViteHostMeta, Yn as WEAPP_VITE_HOST_NAME, Zn as applyWeappViteHostMeta, _ as definePageJson, a as UserConfigFnNoEnvPlain, ar as WeappViteRuntime, at as WeappViteConfig, c as UserConfigFnPromise, d as Component, er as resolveWeappViteHostMeta, f as Page, g as defineComponentJson, h as defineAppJson, i as UserConfigFnNoEnv, l as defineConfig, m as Theme, n as UserConfigExport, o as UserConfigFnObject, p as Sitemap, r as UserConfigFn, s as UserConfigFnObjectPlain, t as UserConfig, u as App, v as defineSitemapJson, y as defineThemeJson } from "./config-6l-p3o-C.mjs";
2
+ import { t as WeappI18nConfig } from "./types-CgZn5X6j.mjs";
3
+ export { type App, type Component, type Page, type Sitemap, type Theme, UserConfig, UserConfigExport, UserConfigFn, UserConfigFnNoEnv, UserConfigFnNoEnvPlain, UserConfigFnObject, UserConfigFnObjectPlain, UserConfigFnPromise, WEAPP_VITE_HOST_NAME, type WeappI18nConfig, type WeappViteConfig, WeappViteHostMeta, type WeappViteRuntime, applyWeappViteHostMeta, createWeappViteHostMeta, defineAppJson, defineComponentJson, defineConfig, definePageJson, defineSitemapJson, defineThemeJson, isWeappViteHost, resolveWeappViteHostMeta };