weapp-vite 6.21.0 → 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.
@@ -1,10 +1,10 @@
1
1
  import { n as applyWeappViteHostMeta } from "./pluginHost--CaeyWpA.mjs";
2
2
  import { n as configureLogger, r as logger_default } from "./logger-mt4mSTqV.mjs";
3
- import { C as isNativeTemplateSource, S as ALL_NATIVE_STYLE_RESOLVER_EXTENSIONS, T as MINI_PROGRAM_PLATFORM_ADAPTERS, _ as jsExtensions, a as findJsonEntry, b as templateExtensions, c as isJsOrTs, d as touch, g as configExtensions, i as findJsEntry, l as isTemplate, n as changeFileExtension, o as findTemplateEntry, p as inlineAutoRoutesImports, r as findCssEntry, s as findVueEntry, t as extractConfigFromVue, v as scriptExtensions, w as isSourceStyleExtension, x as vueExtensions, y as supportedCssLangs } from "./file-Byldwig4.mjs";
3
+ import { C as isNativeTemplateSource, S as ALL_NATIVE_STYLE_RESOLVER_EXTENSIONS, T as MINI_PROGRAM_PLATFORM_ADAPTERS, _ as jsExtensions, a as findJsonEntry, b as templateExtensions, c as isJsOrTs, d as touch, g as configExtensions, i as findJsEntry, l as isTemplate, n as changeFileExtension, o as findTemplateEntry, p as inlineAutoRoutesImports, r as findCssEntry, s as findVueEntry, t as extractConfigFromVue, v as scriptExtensions, w as isSourceStyleExtension, x as vueExtensions, y as supportedCssLangs } from "./file-D0n-Q1ra.mjs";
4
4
  import { createRequire, isBuiltin } from "node:module";
5
5
  import { createDebug } from "obug";
6
6
  import fs, { existsSync, readFileSync, realpathSync } from "node:fs";
7
- import { APP_PRELUDE_CHUNK_MARKER, APP_PRELUDE_GUARD_KEY, APP_PRELUDE_REQUIRE_MARKER, REQUEST_GLOBAL_ACTUALS_KEY, REQUEST_GLOBAL_BUNDLE_HOST_REF, REQUEST_GLOBAL_BUNDLE_MARKER, REQUEST_GLOBAL_BUNDLE_MARKER as REQUEST_GLOBAL_BUNDLE_MARKER$1, REQUEST_GLOBAL_CHUNK_HOST_REF, REQUEST_GLOBAL_CHUNK_MODULE_REF, REQUEST_GLOBAL_EXPOSE_HELPER, REQUEST_GLOBAL_INSTALLER_HOST_REF, REQUEST_GLOBAL_LAZY_CONSTRUCTOR_HELPER, REQUEST_GLOBAL_LAZY_FUNCTION_HELPER, REQUEST_GLOBAL_LOCAL_BINDINGS_MARKER, REQUEST_GLOBAL_LOCAL_BINDINGS_MARKER as REQUEST_GLOBAL_LOCAL_BINDINGS_MARKER$1, REQUEST_GLOBAL_MARK_PLACEHOLDER_HELPER, REQUEST_GLOBAL_PASSIVE_BINDINGS_MARKER, REQUEST_GLOBAL_PASSIVE_BINDINGS_MARKER as REQUEST_GLOBAL_PASSIVE_BINDINGS_MARKER$1, REQUEST_GLOBAL_PLACEHOLDER_KEY, REQUEST_GLOBAL_PRELUDE_GUARD_KEY, REQUEST_GLOBAL_PRELUDE_MARKER, REQUEST_GLOBAL_SYNTHETIC_EXPORT_NAME, REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER, WEAPP_REACT_EVENT_METHOD_NAME, WEAPP_VITE_EXTERNAL_OUTPUT_DIRECTORY, WEAPP_VITE_IMPORT_META_ENV_KEY, WEAPP_VITE_INJECTED_API_IDENTIFIER, WEAPP_VITE_LOGICAL_ENTRY_RESOLVED_PREFIX, WEAPP_VITE_LOGICAL_ENTRY_VIRTUAL_PREFIX, WEAPP_VITE_RUNTIME_CONTRACT_VERSION, WEAPP_VITE_RUNTIME_REACTIVITY_VIRTUAL_ID, WEAPP_VITE_RUNTIME_TEMPLATE_VIRTUAL_ID, WEAPP_VITE_RUNTIME_VIRTUAL_ID, WEAPP_VITE_RUNTIME_VIRTUAL_IDS, WEAPP_VITE_SIDECAR_OWNER_QUERY_MARKER, WEAPP_VITE_SIDECAR_QUERY_MARKER, WEAPP_VITE_SIDECAR_RESOLVED_PREFIX, WEAPP_VITE_SIDECAR_VIRTUAL_PREFIX, WEAPP_VITE_STATEFUL_HMR_BRIDGE_KEY, WEAPP_VITE_STATEFUL_HMR_CLIENT_KEY, WEAPP_VITE_STATEFUL_HMR_CONTROL_FILE, WEAPP_VITE_STATEFUL_HMR_CONTROL_KEY, WEAPP_VITE_STATEFUL_HMR_PRELOAD_FILE, WEAPP_VITE_STATEFUL_HMR_UPDATE_FILE, WEVU_APP_SHELL_COMPONENT_BASE, WEVU_APP_SHELL_TAG_NAME, WEVU_EXPRESSION_ERROR_IDENTIFIER, WEVU_INTERNAL_KEY_IDENTIFIER, WEVU_LAYOUT_BIND_PREFIX, WEVU_PAGE_LAYOUT_CURRENT_NAME_IDENTIFIER, WEVU_PAGE_LAYOUT_CURRENT_PROPS_IDENTIFIER, WEVU_PAGE_LAYOUT_NAME_KEY, WEVU_PAGE_LAYOUT_NEXT_NAME_IDENTIFIER, WEVU_PAGE_LAYOUT_NEXT_PROPS_IDENTIFIER, WEVU_PAGE_LAYOUT_NONE, WEVU_PAGE_LAYOUT_PROPS_KEY, WEVU_PAGE_LAYOUT_SETTER_KEY, WEVU_SCOPED_SLOT_CREATOR_KEY, WEVU_SLOT_FALLBACK_VIRTUAL_HOST_BASE, WEVU_SLOT_FALLBACK_VIRTUAL_HOST_GLOBAL_PATH, WEVU_SLOT_FALLBACK_VIRTUAL_HOST_TAG_NAME, WEVU_SLOT_NAMES_PROP, WEVU_SLOT_OWNER_ID_ATTR, WEVU_SLOT_OWNER_ID_KEY, WEVU_SLOT_OWNER_ID_PROP, WEVU_SLOT_PROPS_ATTR, WEVU_SLOT_SCOPE_ATTR, WEVU_SLOT_SCOPE_KEY } from "@weapp-core/constants";
7
+ import { APP_PRELUDE_CHUNK_MARKER, APP_PRELUDE_GUARD_KEY, APP_PRELUDE_REQUIRE_MARKER, REQUEST_GLOBAL_ACTUALS_KEY, REQUEST_GLOBAL_BUNDLE_HOST_REF, REQUEST_GLOBAL_BUNDLE_MARKER, REQUEST_GLOBAL_BUNDLE_MARKER as REQUEST_GLOBAL_BUNDLE_MARKER$1, REQUEST_GLOBAL_CHUNK_HOST_REF, REQUEST_GLOBAL_CHUNK_MODULE_REF, REQUEST_GLOBAL_EXPOSE_HELPER, REQUEST_GLOBAL_INSTALLER_HOST_REF, REQUEST_GLOBAL_LAZY_CONSTRUCTOR_HELPER, REQUEST_GLOBAL_LAZY_FUNCTION_HELPER, REQUEST_GLOBAL_LOCAL_BINDINGS_MARKER, REQUEST_GLOBAL_LOCAL_BINDINGS_MARKER as REQUEST_GLOBAL_LOCAL_BINDINGS_MARKER$1, REQUEST_GLOBAL_MARK_PLACEHOLDER_HELPER, REQUEST_GLOBAL_PASSIVE_BINDINGS_MARKER, REQUEST_GLOBAL_PASSIVE_BINDINGS_MARKER as REQUEST_GLOBAL_PASSIVE_BINDINGS_MARKER$1, REQUEST_GLOBAL_PLACEHOLDER_KEY, REQUEST_GLOBAL_PRELUDE_GUARD_KEY, REQUEST_GLOBAL_PRELUDE_MARKER, REQUEST_GLOBAL_SYNTHETIC_EXPORT_NAME, REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER, WEAPP_I18N_JS_FILE, WEAPP_I18N_LOCALE_DATA_KEY, WEAPP_I18N_PUBLIC_MODULE_ID, WEAPP_I18N_RUNTIME_MARKER, WEAPP_I18N_VIRTUAL_MODULE_ID, WEAPP_I18N_WXS_FILE, WEAPP_REACT_EVENT_METHOD_NAME, WEAPP_VITE_EXTERNAL_OUTPUT_DIRECTORY, WEAPP_VITE_IMPORT_META_ENV_KEY, WEAPP_VITE_INJECTED_API_IDENTIFIER, WEAPP_VITE_LOGICAL_ENTRY_RESOLVED_PREFIX, WEAPP_VITE_LOGICAL_ENTRY_VIRTUAL_PREFIX, WEAPP_VITE_RUNTIME_CONTRACT_VERSION, WEAPP_VITE_RUNTIME_REACTIVITY_VIRTUAL_ID, WEAPP_VITE_RUNTIME_TEMPLATE_VIRTUAL_ID, WEAPP_VITE_RUNTIME_VIRTUAL_ID, WEAPP_VITE_RUNTIME_VIRTUAL_IDS, WEAPP_VITE_SIDECAR_OWNER_QUERY_MARKER, WEAPP_VITE_SIDECAR_QUERY_MARKER, WEAPP_VITE_SIDECAR_RESOLVED_PREFIX, WEAPP_VITE_SIDECAR_VIRTUAL_PREFIX, WEAPP_VITE_STATEFUL_HMR_BRIDGE_KEY, WEAPP_VITE_STATEFUL_HMR_CLIENT_KEY, WEAPP_VITE_STATEFUL_HMR_CONTROL_FILE, WEAPP_VITE_STATEFUL_HMR_CONTROL_KEY, WEAPP_VITE_STATEFUL_HMR_PRELOAD_FILE, WEAPP_VITE_STATEFUL_HMR_UPDATE_FILE, WEVU_APP_SHELL_COMPONENT_BASE, WEVU_APP_SHELL_TAG_NAME, WEVU_EXPRESSION_ERROR_IDENTIFIER, WEVU_INTERNAL_KEY_IDENTIFIER, WEVU_LAYOUT_BIND_PREFIX, WEVU_PAGE_LAYOUT_CURRENT_NAME_IDENTIFIER, WEVU_PAGE_LAYOUT_CURRENT_PROPS_IDENTIFIER, WEVU_PAGE_LAYOUT_NAME_KEY, WEVU_PAGE_LAYOUT_NEXT_NAME_IDENTIFIER, WEVU_PAGE_LAYOUT_NEXT_PROPS_IDENTIFIER, WEVU_PAGE_LAYOUT_NONE, WEVU_PAGE_LAYOUT_PROPS_KEY, WEVU_PAGE_LAYOUT_SETTER_KEY, WEVU_SCOPED_SLOT_CREATOR_KEY, WEVU_SLOT_FALLBACK_VIRTUAL_HOST_BASE, WEVU_SLOT_FALLBACK_VIRTUAL_HOST_GLOBAL_PATH, WEVU_SLOT_FALLBACK_VIRTUAL_HOST_TAG_NAME, WEVU_SLOT_NAMES_PROP, WEVU_SLOT_OWNER_ID_ATTR, WEVU_SLOT_OWNER_ID_KEY, WEVU_SLOT_OWNER_ID_PROP, WEVU_SLOT_PROPS_ATTR, WEVU_SLOT_SCOPE_ATTR, WEVU_SLOT_SCOPE_KEY } from "@weapp-core/constants";
8
8
  import path, { posix } from "pathe";
9
9
  import { fileURLToPath } from "node:url";
10
10
  import path$1, { normalize, relative, win32 } from "node:path";
@@ -49,6 +49,7 @@ import { objectHash } from "@weapp-core/shared/node";
49
49
  import { wrapPlugin } from "vite-plugin-performance";
50
50
  import { performance as performance$1 } from "node:perf_hooks";
51
51
  import postcss from "postcss";
52
+ import { compileI18nCatalog, generateI18nCatalogModuleSource, generateI18nRuntimeSource, generateI18nWxsSource } from "@weapp-vite/i18n/compiler";
52
53
  import { weappWebPlugin } from "@weapp-vite/web";
53
54
  import { bundleRequire } from "rolldown-require";
54
55
  //#region src/debugger.ts
@@ -9245,7 +9246,10 @@ function createRuntimeState() {
9245
9246
  build: {
9246
9247
  queue: new PQueue({ autoStart: false }),
9247
9248
  npmBuilt: false,
9248
- independent: { outputs: /* @__PURE__ */ new Map() },
9249
+ independent: {
9250
+ outputs: /* @__PURE__ */ new Map(),
9251
+ pendingOutputs: []
9252
+ },
9249
9253
  output: {
9250
9254
  emittedSource: /* @__PURE__ */ new Map(),
9251
9255
  wevuInternalRuntimeFileName: void 0,
@@ -11988,7 +11992,7 @@ const EVENT_NAMES = {
11988
11992
  onTapCapture: "capture-bind:tap"
11989
11993
  };
11990
11994
  const EVENT_PROP_RE = /^on[A-Z]/;
11991
- const IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
11995
+ const IDENTIFIER_RE$1 = /^[A-Z_$][\w$]*$/i;
11992
11996
  function escapeAttribute(value) {
11993
11997
  return value.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;");
11994
11998
  }
@@ -12043,7 +12047,7 @@ function resolveNativeEvent(name) {
12043
12047
  return `${capture ? "capture-bind" : "bind"}:${toKebabCase$1(eventName)}`;
12044
12048
  }
12045
12049
  function renderBindingExpression(slot, name) {
12046
- return IDENTIFIER_RE.test(name) ? `slots.${slot}.${name}` : `slots.${slot}['${name}']`;
12050
+ return IDENTIFIER_RE$1.test(name) ? `slots.${slot}.${name}` : `slots.${slot}['${name}']`;
12047
12051
  }
12048
12052
  function compileAttributes(element, slot, bindingFields, tagKind) {
12049
12053
  const output = [];
@@ -14577,6 +14581,8 @@ function parseWxml(options) {
14577
14581
  const conditionalStack = [];
14578
14582
  const commentTokens = [];
14579
14583
  const inlineWxsTokens = [];
14584
+ const templateTokens = [];
14585
+ const scriptModules = [];
14580
14586
  const scriptModuleTagTokens = [];
14581
14587
  const wxsImportNormalizeTokens = [];
14582
14588
  const removeWxsLangAttrTokens = [];
@@ -14607,6 +14613,11 @@ function parseWxml(options) {
14607
14613
  },
14608
14614
  onattribute(name, value, quote) {
14609
14615
  attrs[name] = value;
14616
+ if (!currentTagName || !isScriptModuleTagName(currentTagName)) templateTokens.push({
14617
+ start: parser.startIndex,
14618
+ end: parser.endIndex + 1,
14619
+ value
14620
+ });
14610
14621
  if (importAttrs && currentTagName) {
14611
14622
  for (const attrName of importAttrs) if (attrName === name) {
14612
14623
  deps.push({
@@ -14666,6 +14677,12 @@ function parseWxml(options) {
14666
14677
  value
14667
14678
  });
14668
14679
  },
14680
+ onopentag(name, attributes) {
14681
+ if (isScriptModuleTagName(name)) scriptModules.push({
14682
+ attrs: attributes,
14683
+ tagName: name
14684
+ });
14685
+ },
14669
14686
  onclosetag(name) {
14670
14687
  currentTagName = tagStack.pop();
14671
14688
  if (currentTagName) {
@@ -14713,6 +14730,11 @@ function parseWxml(options) {
14713
14730
  end: parser.endIndex,
14714
14731
  value: data
14715
14732
  });
14733
+ else templateTokens.push({
14734
+ start: parser.startIndex,
14735
+ end: parser.endIndex + 1,
14736
+ value: data
14737
+ });
14716
14738
  },
14717
14739
  oncomment(data) {
14718
14740
  let match = COMMENT_IFDEF_RE.exec(data);
@@ -14747,6 +14769,8 @@ function parseWxml(options) {
14747
14769
  removalRanges,
14748
14770
  commentTokens,
14749
14771
  inlineWxsTokens,
14772
+ scriptModules,
14773
+ templateTokens,
14750
14774
  wxsImportNormalizeTokens,
14751
14775
  removeWxsLangAttrTokens,
14752
14776
  templateImportNormalizeTokens,
@@ -15502,6 +15526,7 @@ function createIndependentBuilder(configService, buildState) {
15502
15526
  mode: configService.mode,
15503
15527
  configFile: configService.configFilePath,
15504
15528
  cliPlatform: configService.platform,
15529
+ inlineConfig: { weapp: { platform: configService.platform } },
15505
15530
  projectConfigPath: configService.projectConfigPath
15506
15531
  });
15507
15532
  const isolatedConfigService = isolatedCtx.configService;
@@ -18113,8 +18138,9 @@ function createLoadConfig(options) {
18113
18138
  }
18114
18139
  const loadedConfig = loaded?.config ?? {};
18115
18140
  let weappLoaded;
18141
+ const reuseLoadedWeappConfig = shouldReuseLoadedWeappConfig(weappConfigFilePath, loaded?.path);
18116
18142
  if (weappConfigFilePath) {
18117
- if (shouldReuseLoadedWeappConfig(weappConfigFilePath, loaded?.path)) weappLoaded = loaded;
18143
+ if (reuseLoadedWeappConfig) weappLoaded = loaded;
18118
18144
  else try {
18119
18145
  weappLoaded = await loadConfigFileWithFallback({
18120
18146
  command: isDev ? "serve" : "build",
@@ -18130,7 +18156,7 @@ function createLoadConfig(options) {
18130
18156
  throw error;
18131
18157
  }
18132
18158
  }
18133
- const mergedLoadedConfig = weappLoaded?.config ? defu(weappLoaded.config, loadedConfig) : loadedConfig;
18159
+ const mergedLoadedConfig = weappLoaded?.config ? reuseLoadedWeappConfig ? loadedConfig : defu(weappLoaded.config, loadedConfig) : loadedConfig;
18134
18160
  const config = defu(inlineConfig, {
18135
18161
  mode,
18136
18162
  configFile: false
@@ -25170,28 +25196,6 @@ function refreshPartialSharedChunkImporters(bundle, state, entryIds) {
25170
25196
  appendSharedChunkImporters(bundle, state, refreshedEntryIds, previousImporters, previousDependencies);
25171
25197
  }
25172
25198
  //#endregion
25173
- //#region src/plugins/core/helpers/independent.ts
25174
- async function flushIndependentBuilds(state) {
25175
- const { subPackageMeta, pendingIndependentBuilds } = state;
25176
- if (subPackageMeta || pendingIndependentBuilds.length === 0) return;
25177
- const outputs = await Promise.all(pendingIndependentBuilds);
25178
- for (const { rollup } of outputs) {
25179
- const bundleOutputs = Array.isArray(rollup?.output) ? rollup.output : [];
25180
- for (const output of bundleOutputs) if (output.type === "chunk") this.emitFile({
25181
- type: "asset",
25182
- source: output.code,
25183
- fileName: output.fileName,
25184
- name: output.name
25185
- });
25186
- else this.emitFile({
25187
- type: "asset",
25188
- source: output.source,
25189
- fileName: output.fileName
25190
- });
25191
- }
25192
- state.pendingIndependentBuilds = [];
25193
- }
25194
- //#endregion
25195
25199
  //#region src/runtime/config/internal/injectRequestGlobals.ts
25196
25200
  const FULL_REQUEST_GLOBAL_TARGETS = [
25197
25201
  "fetch",
@@ -25945,9 +25949,6 @@ function relativeToRoot(pathname, root) {
25945
25949
  if (pathname === root) return "";
25946
25950
  if (pathname.startsWith(`${root}/`)) return pathname.slice(root.length + 1);
25947
25951
  }
25948
- function isMainAppStyleFile(fileName) {
25949
- return !fileName.includes("/") && path.posix.basename(fileName, path.posix.extname(fileName)) === "app";
25950
- }
25951
25952
  function getStyleMatcher(entry) {
25952
25953
  const cached = styleMatcherCache.get(entry);
25953
25954
  if (cached) return cached;
@@ -25975,7 +25976,6 @@ function findSharedStylesForModule(modulePath, fileName, sharedStyles) {
25975
25976
  for (const [root, entries] of sharedStyles.entries()) {
25976
25977
  const normalizedRoot = normalizeRoot(root);
25977
25978
  if (root && !normalizedRoot) continue;
25978
- if (!normalizedRoot && isMainAppStyleFile(sanitizedFile)) continue;
25979
25979
  if (!isWithinRoot(sanitizedFile, normalizedRoot)) continue;
25980
25980
  const relativeModule = relativeToRoot(sanitizedModule, normalizedRoot);
25981
25981
  const relativeFile = relativeToRoot(sanitizedFile, normalizedRoot);
@@ -26441,6 +26441,296 @@ function css(ctx) {
26441
26441
  }];
26442
26442
  }
26443
26443
  //#endregion
26444
+ //#region src/i18n/config.ts
26445
+ const IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
26446
+ function normalizeName(value, fallback, field) {
26447
+ const resolved = value?.trim() || fallback;
26448
+ if (!IDENTIFIER_RE.test(resolved)) throw new Error(`weapp.i18n.${field} 必须是合法标识符,当前值为 \`${resolved}\`。`);
26449
+ return resolved;
26450
+ }
26451
+ function resolveWeappI18nConfig(config) {
26452
+ if (!config || typeof config !== "object") throw new Error("weapp.i18n 必须是配置对象。");
26453
+ const defaultLocale = config.defaultLocale?.trim();
26454
+ if (!defaultLocale) throw new Error("weapp.i18n.defaultLocale 为必填项。");
26455
+ const include = (Array.isArray(config.include) ? config.include : [config.include ?? "**/i18n/*.json"]).map((item) => item.trim()).filter(Boolean);
26456
+ if (!include.length) throw new Error("weapp.i18n.include 至少需要一个有效 glob。");
26457
+ return {
26458
+ defaultLocale,
26459
+ fallbackLocale: config.fallbackLocale?.trim() || defaultLocale,
26460
+ include,
26461
+ functionName: normalizeName(config.functionName, "t", "functionName"),
26462
+ moduleName: normalizeName(config.moduleName, "i18n", "moduleName")
26463
+ };
26464
+ }
26465
+ //#endregion
26466
+ //#region src/i18n/template.ts
26467
+ function resolveAssetSource(fileName, assetFileName) {
26468
+ const relative = path.posix.relative(path.posix.dirname(fileName), assetFileName);
26469
+ return relative.startsWith(".") ? relative : `./${relative}`;
26470
+ }
26471
+ function collectCallReplacements(expression, expressionOffset, options) {
26472
+ let ast;
26473
+ try {
26474
+ ast = parse$3(`(${expression})`, { sourceType: "module" });
26475
+ } catch {
26476
+ return [];
26477
+ }
26478
+ const calls = [];
26479
+ traverse(ast, { CallExpression(callPath) {
26480
+ const node = callPath.node;
26481
+ if (node.callee.type !== "Identifier" || node.callee.name !== options.functionName) return;
26482
+ const start = (node.start ?? 1) - 1;
26483
+ const end = (node.end ?? 1) - 1;
26484
+ calls.push({
26485
+ end,
26486
+ start
26487
+ });
26488
+ } });
26489
+ if (!calls.length) return [];
26490
+ const renderSegment = (start, end) => {
26491
+ const nestedCalls = calls.filter((call) => call.start >= start && call.end <= end).filter((call) => {
26492
+ return !calls.some((parent) => parent !== call && parent.start >= start && parent.end <= end && parent.start <= call.start && parent.end >= call.end);
26493
+ }).sort((left, right) => left.start - right.start);
26494
+ let cursor = start;
26495
+ let rendered = "";
26496
+ for (const call of nestedCalls) {
26497
+ rendered += expression.slice(cursor, call.start);
26498
+ const openParen = expression.slice(call.start, call.end).indexOf("(");
26499
+ const argsStart = call.start + openParen + 1;
26500
+ const args = openParen >= 0 ? renderSegment(argsStart, call.end - 1).trim() : "";
26501
+ rendered += `${options.moduleName}.t(${options.localeDataKey}${args ? `, ${args}` : ""})`;
26502
+ cursor = call.end;
26503
+ }
26504
+ return rendered + expression.slice(cursor, end);
26505
+ };
26506
+ return [{
26507
+ start: expressionOffset,
26508
+ end: expressionOffset + expression.length,
26509
+ value: renderSegment(0, expression.length)
26510
+ }];
26511
+ }
26512
+ function collectMustacheRanges(source, start, end) {
26513
+ const ranges = [];
26514
+ for (let cursor = start; cursor < end - 1;) {
26515
+ if (source[cursor] !== "{" || source[cursor + 1] !== "{") {
26516
+ cursor++;
26517
+ continue;
26518
+ }
26519
+ const expressionStart = cursor + 2;
26520
+ let expressionEnd = expressionStart;
26521
+ let braceDepth = 0;
26522
+ let escaped = false;
26523
+ let quote = "";
26524
+ for (; expressionEnd < end - 1; expressionEnd++) {
26525
+ const char = source[expressionEnd];
26526
+ if (quote) {
26527
+ if (escaped) escaped = false;
26528
+ else if (char === "\\") escaped = true;
26529
+ else if (char === quote) quote = "";
26530
+ continue;
26531
+ }
26532
+ if (char === "'" || char === "\"" || char === "`") quote = char;
26533
+ else if (char === "{") braceDepth++;
26534
+ else if (char === "}" && braceDepth > 0) braceDepth--;
26535
+ else if (char === "}" && source[expressionEnd + 1] === "}") {
26536
+ ranges.push({
26537
+ expressionEnd,
26538
+ expressionStart
26539
+ });
26540
+ cursor = expressionEnd + 2;
26541
+ break;
26542
+ }
26543
+ }
26544
+ if (expressionEnd >= end - 1) break;
26545
+ }
26546
+ return ranges;
26547
+ }
26548
+ function transformI18nTemplate(source, options) {
26549
+ const token = scanWxml(source, { platform: "weapp" });
26550
+ const replacements = [];
26551
+ for (const templateToken of token.templateTokens ?? []) for (const range of collectMustacheRanges(source, templateToken.start, templateToken.end)) {
26552
+ const expression = source.slice(range.expressionStart, range.expressionEnd);
26553
+ replacements.push(...collectCallReplacements(expression, range.expressionStart, options));
26554
+ }
26555
+ if (!replacements.length) return source;
26556
+ if (token.scriptModules?.some((scriptModule) => {
26557
+ return scriptModule.attrs.module === options.moduleName;
26558
+ })) throw new Error(`${options.fileName} 已存在 module=\"${options.moduleName}\" 的 WXS 模块,无法注入 i18n。`);
26559
+ const ms = new MagicString(source);
26560
+ for (const replacement of replacements.sort((left, right) => right.start - left.start)) ms.update(replacement.start, replacement.end, replacement.value);
26561
+ const src = resolveAssetSource(options.fileName, options.assetFileName);
26562
+ return `<wxs module="${options.moduleName}" src="${src}"/>\n${ms.toString()}`;
26563
+ }
26564
+ //#endregion
26565
+ //#region src/plugins/i18n.ts
26566
+ const TEMPLATE_MODULE_RE = /\.(?:vue|wxml)(?:\?|$)/;
26567
+ function withPackageRoot(root, fileName) {
26568
+ const normalizedRoot = root.replace(/^\/+|\/+$/g, "");
26569
+ return normalizedRoot ? `${normalizedRoot}/${fileName}` : fileName;
26570
+ }
26571
+ function resolveCurrentPackageRoot(subPackageMeta) {
26572
+ return subPackageMeta?.subPackage.root?.replace(/^\/+|\/+$/g, "") ?? "";
26573
+ }
26574
+ function resolveOutputPackageRoot(ctx, fileName, subPackageMeta) {
26575
+ const currentRoot = resolveCurrentPackageRoot(subPackageMeta);
26576
+ if (currentRoot) return currentRoot;
26577
+ const normalized = toPosixPath(fileName).replace(/^\/+/, "");
26578
+ return [...ctx.scanService.subPackageMap.keys()].map((root) => root.replace(/^\/+|\/+$/g, "")).filter((root) => normalized === root || normalized.startsWith(`${root}/`)).sort((left, right) => right.length - left.length)[0] ?? "";
26579
+ }
26580
+ function resolveEmittedPackageRoots(ctx, subPackageMeta) {
26581
+ const currentRoot = resolveCurrentPackageRoot(subPackageMeta);
26582
+ if (currentRoot) return [currentRoot];
26583
+ return ["", ...[...ctx.scanService.subPackageMap.keys()].filter((root) => !ctx.scanService.independentSubPackageMap.has(root))];
26584
+ }
26585
+ async function loadI18nCatalog(ctx, config) {
26586
+ const root = ctx.configService.absoluteSrcRoot;
26587
+ const matcher = picomatch(config.include, { dot: false });
26588
+ const files = (await new fdir({
26589
+ includeDirs: false,
26590
+ pathSeparator: "/"
26591
+ }).withFullPaths().crawl(root).withPromise()).filter((file) => matcher(toPosixPath(path.relative(root, file)))).sort();
26592
+ if (!files.length) throw new Error(`weapp.i18n 未找到 locale 文件,include: ${config.include.join(", ")}。`);
26593
+ const inputs = [];
26594
+ for (const filePath of files) {
26595
+ let messages;
26596
+ try {
26597
+ messages = JSON.parse(await fs$1.readFile(filePath, "utf8"));
26598
+ } catch (error) {
26599
+ throw new Error(`无法解析 i18n 文件 \`${ctx.configService.relativeCwd(filePath)}\`:${String(error)}`);
26600
+ }
26601
+ inputs.push({
26602
+ filePath: ctx.configService.relativeCwd(filePath),
26603
+ locale: path.basename(filePath, path.extname(filePath)),
26604
+ messages
26605
+ });
26606
+ }
26607
+ return {
26608
+ catalog: compileI18nCatalog(inputs, config),
26609
+ files
26610
+ };
26611
+ }
26612
+ function matchesI18nLocaleFile(ctx, config, filePath) {
26613
+ const relativePath = toPosixPath(path.relative(ctx.configService.absoluteSrcRoot, filePath));
26614
+ return !relativePath.startsWith("../") && picomatch(config.include, { dot: false })(relativePath);
26615
+ }
26616
+ function transformI18nOutputTemplate(ctx, fileName, source, subPackageMeta) {
26617
+ const rawConfig = ctx.configService.weappViteConfig?.i18n;
26618
+ if (!rawConfig || ctx.configService.platform !== "weapp") return source;
26619
+ const config = resolveWeappI18nConfig(rawConfig);
26620
+ return transformI18nTemplate(source, {
26621
+ assetFileName: withPackageRoot(resolveOutputPackageRoot(ctx, fileName, subPackageMeta), WEAPP_I18N_WXS_FILE),
26622
+ fileName,
26623
+ functionName: config.functionName,
26624
+ localeDataKey: WEAPP_I18N_LOCALE_DATA_KEY,
26625
+ moduleName: config.moduleName
26626
+ });
26627
+ }
26628
+ function i18n(ctx, subPackageMeta) {
26629
+ const state = { files: [] };
26630
+ const resolvedId = `\0${WEAPP_I18N_VIRTUAL_MODULE_ID}:${resolveCurrentPackageRoot(subPackageMeta) || "main"}`;
26631
+ async function refreshCatalog(pluginContext) {
26632
+ if (!state.config) return;
26633
+ const loaded = await loadI18nCatalog(ctx, state.config);
26634
+ state.catalog = loaded.catalog;
26635
+ state.files = loaded.files;
26636
+ for (const file of state.files) pluginContext?.addWatchFile?.(file);
26637
+ }
26638
+ return [{
26639
+ name: "weapp-vite:i18n",
26640
+ enforce: "pre",
26641
+ async buildStart() {
26642
+ const rawConfig = ctx.configService.weappViteConfig?.i18n;
26643
+ if (!rawConfig) return;
26644
+ if (ctx.configService.platform !== "weapp") throw new Error("weapp.i18n v1 仅支持 platform = \"weapp\"。");
26645
+ state.config = resolveWeappI18nConfig(rawConfig);
26646
+ await refreshCatalog(this);
26647
+ this.emitFile({
26648
+ type: "chunk",
26649
+ id: WEAPP_I18N_PUBLIC_MODULE_ID,
26650
+ fileName: withPackageRoot(resolveCurrentPackageRoot(subPackageMeta), WEAPP_I18N_JS_FILE),
26651
+ preserveSignature: "exports-only"
26652
+ });
26653
+ },
26654
+ watchChange(id) {
26655
+ if (state.config && matchesI18nLocaleFile(ctx, state.config, id)) state.catalog = void 0;
26656
+ },
26657
+ async handleHotUpdate(hotContext) {
26658
+ if (!state.config || !matchesI18nLocaleFile(ctx, state.config, hotContext.file)) return;
26659
+ await refreshCatalog();
26660
+ const affectedModules = [];
26661
+ const runtimeModule = hotContext.server.moduleGraph.getModuleById(resolvedId);
26662
+ if (runtimeModule) {
26663
+ hotContext.server.moduleGraph.invalidateModule(runtimeModule);
26664
+ affectedModules.push(runtimeModule);
26665
+ }
26666
+ for (const module of hotContext.server.moduleGraph.idToModuleMap.values()) if (module.id && TEMPLATE_MODULE_RE.test(module.id)) {
26667
+ hotContext.server.moduleGraph.invalidateModule(module);
26668
+ affectedModules.push(module);
26669
+ }
26670
+ return affectedModules;
26671
+ },
26672
+ resolveId(id) {
26673
+ if (id === WEAPP_I18N_PUBLIC_MODULE_ID && ctx.configService.weappViteConfig?.i18n) return resolvedId;
26674
+ },
26675
+ load(id) {
26676
+ if (id !== resolvedId) return;
26677
+ if (!state.catalog) throw new Error("i18n runtime 在 locale catalog 初始化前被加载。");
26678
+ return generateI18nRuntimeSource(state.catalog);
26679
+ },
26680
+ generateBundle() {
26681
+ if (!state.catalog) return;
26682
+ const wxsSource = generateI18nWxsSource(state.catalog);
26683
+ const catalogSource = generateI18nCatalogModuleSource(state.catalog);
26684
+ const currentRoot = resolveCurrentPackageRoot(subPackageMeta);
26685
+ for (const root of resolveEmittedPackageRoots(ctx, subPackageMeta)) {
26686
+ this.emitFile({
26687
+ type: "asset",
26688
+ fileName: withPackageRoot(root, WEAPP_I18N_WXS_FILE),
26689
+ source: wxsSource
26690
+ });
26691
+ if (root !== currentRoot) this.emitFile({
26692
+ type: "asset",
26693
+ fileName: withPackageRoot(root, WEAPP_I18N_JS_FILE),
26694
+ source: `${catalogSource}// ${WEAPP_I18N_RUNTIME_MARKER}\n`
26695
+ });
26696
+ }
26697
+ }
26698
+ }];
26699
+ }
26700
+ //#endregion
26701
+ //#region src/plugins/outputFinalizer/independent.ts
26702
+ function toEmittedAsset(output) {
26703
+ if (output.type === "chunk") return {
26704
+ type: "asset",
26705
+ fileName: output.fileName,
26706
+ name: output.name,
26707
+ source: output.code
26708
+ };
26709
+ const name = output.names[0] ?? output.name;
26710
+ const originalFileName = output.originalFileNames[0] ?? output.originalFileName;
26711
+ return {
26712
+ type: "asset",
26713
+ fileName: output.fileName,
26714
+ source: output.source,
26715
+ ...name ? { name } : {},
26716
+ ...originalFileName ? { originalFileName } : {},
26717
+ needsCodeReference: output.needsCodeReference
26718
+ };
26719
+ }
26720
+ function getBundleOutputs(output) {
26721
+ return Array.isArray(output.output) ? output.output : [];
26722
+ }
26723
+ async function flushIndependentOutputs(ctx, subPackageMeta, emitAsset) {
26724
+ if (subPackageMeta) return;
26725
+ const independentState = ctx.runtimeState?.build?.independent;
26726
+ if (!independentState) return;
26727
+ const pendingOutputs = independentState.pendingOutputs;
26728
+ if (pendingOutputs.length === 0) return;
26729
+ independentState.pendingOutputs = [];
26730
+ const outputs = await Promise.all(pendingOutputs);
26731
+ for (const output of outputs) for (const bundleOutput of getBundleOutputs(output)) emitAsset(toEmittedAsset(bundleOutput));
26732
+ }
26733
+ //#endregion
26444
26734
  //#region src/plugins/outputFinalizer.ts
26445
26735
  const PREPROCESSOR_STYLE_ASSET_RE = /\.(?:less|sass|scss|styl|stylus|pcss|postcss|sss)$/i;
26446
26736
  const TEMPLATE_ASSET_RE = /\.(?:wxml|axml|swan|ttml|jxml|qml|ksml|xhsml)$/i;
@@ -26569,22 +26859,23 @@ function normalizePreprocessorStyleAssets(bundle, styleExtension, emitAsset) {
26569
26859
  if (!styleExtension) return;
26570
26860
  normalizePreprocessorStyleAssetEntries(bundle, collectOutputFinalizerAssetEntries(bundle).preprocessorStyleAssets, styleExtension, emitAsset);
26571
26861
  }
26572
- function normalizeTemplateAssetEntries(ctx, entries) {
26862
+ function normalizeTemplateAssetEntries(ctx, entries, subPackageMeta) {
26573
26863
  const { configService } = ctx;
26574
- for (const { output } of entries) {
26864
+ for (const { bundleFileName, output } of entries) {
26575
26865
  const source = output.source;
26576
26866
  const code = typeof source === "string" ? source : source instanceof Uint8Array ? Buffer.from(source).toString("utf8") : void 0;
26577
26867
  if (code === void 0) continue;
26578
- if (!mayNeedTemplateNormalization(code, configService?.platform)) continue;
26579
- const result = handleWxml(scanWxml(code, { platform: configService?.platform }), {
26868
+ let normalized = code;
26869
+ if (mayNeedTemplateNormalization(code, configService?.platform)) normalized = handleWxml(scanWxml(code, { platform: configService?.platform }), {
26580
26870
  scriptModuleExtension: configService?.outputExtensions?.wxs,
26581
26871
  scriptModuleTag: resolveScriptModuleTagName({
26582
26872
  platform: configService?.platform,
26583
26873
  scriptModuleExtension: configService?.outputExtensions?.wxs
26584
26874
  }),
26585
26875
  templateExtension: configService?.outputExtensions?.wxml
26586
- });
26587
- if (result.code !== code) output.source = result.code;
26876
+ }).code;
26877
+ const transformed = transformI18nOutputTemplate(ctx, output.fileName || bundleFileName, normalized, subPackageMeta);
26878
+ if (transformed !== code) output.source = transformed;
26588
26879
  }
26589
26880
  }
26590
26881
  function pruneUneventedDevHmrChunks(ctx, bundle) {
@@ -26615,7 +26906,7 @@ function pruneUnchangedDevHmrOutputs(ctx, bundle, rewriteOptions, options) {
26615
26906
  cache.set(fileName, source);
26616
26907
  }
26617
26908
  }
26618
- function createOutputFinalizerPlugin(ctx) {
26909
+ function createOutputFinalizerPlugin(ctx, subPackageMeta) {
26619
26910
  const wevuRuntimeRewriteOptions = {
26620
26911
  get runtimeFileName() {
26621
26912
  return ctx.runtimeState?.build?.output?.wevuInternalRuntimeFileName;
@@ -26643,7 +26934,7 @@ function createOutputFinalizerPlugin(ctx) {
26643
26934
  enforce: "post",
26644
26935
  generateBundle: {
26645
26936
  order: "post",
26646
- handler(_options, bundle) {
26937
+ async handler(_options, bundle) {
26647
26938
  const outputBundle = bundle;
26648
26939
  rewriteWevuInternalRuntimeImports(bundle, wevuRuntimeRewriteOptions);
26649
26940
  stabilizeWevuRuntimeChunkAccess(bundle);
@@ -26651,9 +26942,10 @@ function createOutputFinalizerPlugin(ctx) {
26651
26942
  normalizeGraphOnlyAssets(ctx, outputBundle, (asset) => this.emitFile(asset));
26652
26943
  const assetEntries = collectOutputFinalizerAssetEntries(outputBundle);
26653
26944
  normalizePreprocessorStyleAssetEntries(outputBundle, assetEntries.preprocessorStyleAssets, ctx.configService.outputExtensions?.wxss, (asset) => this.emitFile(asset));
26654
- normalizeTemplateAssetEntries(ctx, assetEntries.templateAssets);
26945
+ normalizeTemplateAssetEntries(ctx, assetEntries.templateAssets, subPackageMeta);
26655
26946
  pruneUnchangedDevHmrOutputs(ctx, outputBundle, wevuRuntimeRewriteOptions, { runtimeRewriteDone: true });
26656
26947
  syncOutputChunkSourceMapAssets(outputBundle);
26948
+ await flushIndependentOutputs(ctx, subPackageMeta, (asset) => this.emitFile(asset));
26657
26949
  }
26658
26950
  }
26659
26951
  };
@@ -28156,7 +28448,6 @@ function createGenerateBundleHook(state, isPluginBuild) {
28156
28448
  ctx.moduleGraphService?.bindPluginContext(this);
28157
28449
  const rolldownBundle = bundle;
28158
28450
  const scriptAnalysisCache = /* @__PURE__ */ new WeakMap();
28159
- await flushIndependentBuilds.call(this, state);
28160
28451
  const hasChunkOutput = pruneHmrMetadataOnlyChunks(rolldownBundle, state);
28161
28452
  await emitCurrentStyleSidecarAsset.call(this, state, rolldownBundle);
28162
28453
  const assetOnlyDevHmrBundle = isAssetOnlyDevHmrBundle(hasChunkOutput, state);
@@ -28779,7 +29070,6 @@ function createOptionsHook(state) {
28779
29070
  const { scanService, configService, buildService } = ctx;
28780
29071
  return async function options(options) {
28781
29072
  if (this) ctx.moduleGraphService?.bindPluginContext(this);
28782
- state.pendingIndependentBuilds = [];
28783
29073
  state.hmrRootInputIds ??= /* @__PURE__ */ new Set();
28784
29074
  state.hmrRootInputIds.clear();
28785
29075
  let scannedInput;
@@ -28824,21 +29114,17 @@ function createOptionsHook(state) {
28824
29114
  type: "app"
28825
29115
  }]));
28826
29116
  else {
29117
+ const independentState = ctx.runtimeState.build.independent;
29118
+ independentState.pendingOutputs = [];
28827
29119
  scanService.loadSubPackages();
28828
29120
  const dirtyIndependentRoots = scanService.drainIndependentDirtyRoots();
28829
- const pendingIndependentBuilds = [];
28830
29121
  const previousSubPackageRoot = configService.currentSubPackageRoot;
28831
29122
  for (const root of dirtyIndependentRoots) {
28832
29123
  const meta = scanService.independentSubPackageMap.get(root);
28833
29124
  if (!meta) continue;
28834
- const buildTask = buildService.buildIndependentBundle(root, meta).then((rollup) => {
28835
- return {
28836
- meta,
28837
- rollup
28838
- };
28839
- });
29125
+ const buildTask = buildService.buildIndependentBundle(root, meta);
28840
29126
  buildTask.catch(() => {});
28841
- pendingIndependentBuilds.push(buildTask);
29127
+ independentState.pendingOutputs.push(buildTask);
28842
29128
  try {
28843
29129
  await buildTask;
28844
29130
  } catch {}
@@ -28847,7 +29133,6 @@ function createOptionsHook(state) {
28847
29133
  ...configService.options,
28848
29134
  currentSubPackageRoot: previousSubPackageRoot
28849
29135
  };
28850
- state.pendingIndependentBuilds = pendingIndependentBuilds;
28851
29136
  scannedInput = await collectMainLogicalInputs(state, appEntry);
28852
29137
  }
28853
29138
  }
@@ -29998,7 +30283,6 @@ function weappVite(ctx, subPackageMeta) {
29998
30283
  jsonEmitFilesMap,
29999
30284
  resolvedEntryMap,
30000
30285
  requireAsyncEmittedChunks: /* @__PURE__ */ new Set(),
30001
- pendingIndependentBuilds: [],
30002
30286
  watchFilesSnapshot: [],
30003
30287
  buildTarget,
30004
30288
  hmrState,
@@ -30788,6 +31072,20 @@ function shouldDelegateComponentRegistration(ctx, vuePath, isPage, isApp, config
30788
31072
  function isVueTransformSourceMapEnabled(configService) {
30789
31073
  return Boolean(configService.inlineConfig?.build?.sourcemap);
30790
31074
  }
31075
+ function resolveSfcStylePreprocessOptions(configService) {
31076
+ const options = configService.inlineConfig?.css?.preprocessorOptions;
31077
+ if (!options) return;
31078
+ const root = path.resolve(configService.cwd, configService.inlineConfig?.root ?? ".");
31079
+ const nodeModules = path.resolve(root, "node_modules");
31080
+ return Object.fromEntries(Object.entries(options).map(([language, languageOptions]) => {
31081
+ if (!["sass", "scss"].includes(language)) return [language, languageOptions];
31082
+ const loadPaths = Array.isArray(languageOptions.loadPaths) ? languageOptions.loadPaths.filter((value) => typeof value === "string") : [];
31083
+ return [language, {
31084
+ ...languageOptions,
31085
+ loadPaths: Array.from(/* @__PURE__ */ new Set([...loadPaths, nodeModules]))
31086
+ }];
31087
+ }));
31088
+ }
30791
31089
  function resolveVueTemplatePlatformOptions(options) {
30792
31090
  const supportsWxs = options.wxsEnabled && typeof options.wxsExtension === "string" && options.wxsExtension.length > 0;
30793
31091
  const resolvedWxsExtension = supportsWxs ? options.wxsExtension : void 0;
@@ -30840,6 +31138,8 @@ function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, conf
30840
31138
  const objectLiteralBindMode = configService.weappViteConfig?.vue?.template?.objectLiteralBindMode ?? "runtime";
30841
31139
  const mustacheInterpolation = configService.weappViteConfig?.vue?.template?.mustacheInterpolation ?? "compact";
30842
31140
  const functionPropNames = configService.weappViteConfig?.vue?.template?.functionPropNames;
31141
+ const i18nConfig = configService.platform === "weapp" ? configService.weappViteConfig?.i18n : void 0;
31142
+ const templateSafeCallNames = i18nConfig ? [i18nConfig.functionName ?? "t"] : void 0;
30843
31143
  const formatWxmlConfig = configService.weappViteConfig?.vue?.template?.formatWxml ?? "auto";
30844
31144
  const formatWxml = formatWxmlConfig === "auto" ? configService.isDev : formatWxmlConfig;
30845
31145
  const wxsEnabled = configService.weappViteConfig?.wxs !== false;
@@ -30963,10 +31263,12 @@ function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, conf
30963
31263
  objectLiteralBindMode,
30964
31264
  mustacheInterpolation,
30965
31265
  functionPropNames,
31266
+ templateSafeCallNames,
30966
31267
  formatWxml,
30967
31268
  wxsExtension: templatePlatformOptions.wxsExtension,
30968
31269
  classStyleWxsSrc
30969
31270
  },
31271
+ style: { preprocessOptions: resolveSfcStylePreprocessOptions(configService) },
30970
31272
  json: {
30971
31273
  kind: jsonKind,
30972
31274
  defaults: jsonConfig?.defaults,
@@ -31349,9 +31651,17 @@ async function loadTransformStyleBlock(options) {
31349
31651
  if (!block) return null;
31350
31652
  const dependencies = syncVueSfcStyleDependencies(ctx, filename, styles);
31351
31653
  ctx.moduleGraphService.replaceEntryDependencies(filename, "style", dependencies);
31654
+ const compiled = await compileVueStyleToWxss(block, {
31655
+ id: generateScopedId(filename),
31656
+ filename,
31657
+ scoped: block.scoped,
31658
+ modules: block.module,
31659
+ preprocessOptions: resolveSfcStylePreprocessOptions(configService)?.[block.lang || "css"]
31660
+ });
31661
+ for (const dependency of compiled.dependencies ?? []) pluginCtx.addWatchFile?.(dependency);
31352
31662
  return {
31353
- code: block.content,
31354
- map: null
31663
+ code: compiled.code,
31664
+ map: compiled.map ? JSON.parse(compiled.map) : null
31355
31665
  };
31356
31666
  }
31357
31667
  //#endregion
@@ -31505,18 +31815,20 @@ function logTransformFileError(filename, error) {
31505
31815
  function hasCssModules(styleBlocks) {
31506
31816
  return styleBlocks?.some((styleBlock) => Boolean(styleBlock.module)) === true;
31507
31817
  }
31508
- function refreshStyleOnlyVueTransformResult(result, filename, styleBlocks) {
31818
+ async function refreshStyleOnlyVueTransformResult(result, filename, styleBlocks, stylePreprocessOptions) {
31509
31819
  if (!styleBlocks || hasCssModules(styleBlocks)) return false;
31510
31820
  if (!styleBlocks.length) {
31511
31821
  result.style = void 0;
31512
31822
  return true;
31513
31823
  }
31514
31824
  const scopedId = generateScopedId(filename);
31515
- result.style = styleBlocks.map((styleBlock) => compileVueStyleToWxss(styleBlock, {
31825
+ result.style = (await Promise.all(styleBlocks.map(async (styleBlock) => await compileVueStyleToWxss(styleBlock, {
31516
31826
  id: scopedId,
31827
+ filename,
31517
31828
  scoped: styleBlock.scoped,
31518
- modules: styleBlock.module
31519
- }).code.trim()).filter(Boolean).join("\n\n") || void 0;
31829
+ modules: styleBlock.module,
31830
+ preprocessOptions: stylePreprocessOptions?.[styleBlock.lang || "css"]
31831
+ })))).map((result) => result.code.trim()).filter(Boolean).join("\n\n") || void 0;
31520
31832
  return true;
31521
31833
  }
31522
31834
  //#endregion
@@ -31666,7 +31978,7 @@ async function refreshCompiledVueEntryCacheInDev(options) {
31666
31978
  source,
31667
31979
  checkMtime: configService.isDev
31668
31980
  });
31669
- if (!refreshStyleOnlyVueTransformResult(cached.result, filename, descriptor.styles)) cached.styleIndependentSignature = void 0;
31981
+ if (!await refreshStyleOnlyVueTransformResult(cached.result, filename, descriptor.styles, resolveSfcStylePreprocessOptions(configService))) cached.styleIndependentSignature = void 0;
31670
31982
  else {
31671
31983
  cached.source = source;
31672
31984
  cached.styleIndependentSignature = currentStyleIndependentSignature;
@@ -32482,7 +32794,7 @@ async function tryReuseVueCompilation(options) {
32482
32794
  pluginCtx,
32483
32795
  configService
32484
32796
  }));
32485
- if (!refreshStyleOnlyVueTransformResult(cachedResult, filename, refreshedStyleBlocks)) {
32797
+ if (!await refreshStyleOnlyVueTransformResult(cachedResult, filename, refreshedStyleBlocks, resolveSfcStylePreprocessOptions(configService))) {
32486
32798
  cachedCompilation.styleIndependentSignature = void 0;
32487
32799
  canReturnCachedCompilation = false;
32488
32800
  } else {
@@ -32524,7 +32836,7 @@ async function tryReuseVueCompilation(options) {
32524
32836
  pluginCtx,
32525
32837
  configService
32526
32838
  }));
32527
- if (!refreshStyleOnlyVueTransformResult(cachedResult, filename, styleBlocks)) cachedCompilation.styleIndependentSignature = void 0;
32839
+ if (!await refreshStyleOnlyVueTransformResult(cachedResult, filename, styleBlocks, resolveSfcStylePreprocessOptions(configService))) cachedCompilation.styleIndependentSignature = void 0;
32528
32840
  else {
32529
32841
  cachedCompilation.source = source;
32530
32842
  cachedCompilation.result = cachedResult;
@@ -33164,8 +33476,8 @@ function vitePluginWeapp(ctx, subPackageMeta) {
33164
33476
  if (autoRoutesEnabled && !libModeEnabled) groups.push(autoRoutes(ctx));
33165
33477
  groups.push(autoImport(ctx));
33166
33478
  }
33167
- groups.push(weappVite(ctx, subPackageMeta), wxs(ctx), css(ctx));
33168
- groups.push([createOutputFinalizerPlugin(ctx)]);
33479
+ groups.push(i18n(ctx, subPackageMeta), weappVite(ctx, subPackageMeta), wxs(ctx), css(ctx));
33480
+ groups.push([createOutputFinalizerPlugin(ctx, subPackageMeta)]);
33169
33481
  const assembled = attachRuntimePlugins(ctx, flatten(groups));
33170
33482
  if (subPackageMeta) return assembled;
33171
33483
  return applyInspect(ctx, assembled);
@@ -34188,7 +34500,7 @@ async function loadAppEntry(ctx, scanState) {
34188
34500
  const { path: appEntryPath } = appEntry;
34189
34501
  let configFromVue;
34190
34502
  if (!appConfigFile && vueAppPath) {
34191
- const { extractConfigFromVue } = await import("./file-C-jjrMsb.mjs");
34503
+ const { extractConfigFromVue } = await import("./file-DPQbjCzZ.mjs");
34192
34504
  configFromVue = await extractConfigFromVue(vueAppPath);
34193
34505
  if (configFromVue) appConfigFile = vueAppPath;
34194
34506
  }
@@ -34460,6 +34772,13 @@ function inferScopeFromRelativePath(relativePath) {
34460
34772
  }
34461
34773
  //#endregion
34462
34774
  //#region src/runtime/scanPlugin/styleEntries/index.ts
34775
+ function hasExplicitIncludePattern(include, normalizedRoot) {
34776
+ return (include === void 0 ? [] : Array.isArray(include) ? include : [include]).some((pattern) => normalizePattern(pattern, normalizedRoot) !== void 0);
34777
+ }
34778
+ function appendExcludePattern(exclude, pattern) {
34779
+ if (exclude === void 0) return [pattern];
34780
+ return Array.isArray(exclude) ? [...exclude, pattern] : [exclude, pattern];
34781
+ }
34463
34782
  function isSupportedSharedStyleExtension(absolutePath) {
34464
34783
  return SUPPORTED_SHARED_STYLE_EXTS.has(path.extname(absolutePath).toLowerCase());
34465
34784
  }
@@ -34502,6 +34821,7 @@ function normalizeStyleEntries(styles, root, configService, options) {
34502
34821
  const posixOutput = toPosixPath(outputRelativePath);
34503
34822
  addStyleEntry({
34504
34823
  ...descriptor,
34824
+ exclude: options.excludeRootAppByDefault && !hasExplicitIncludePattern(descriptor.include, normalizedRoot) ? appendExcludePattern(descriptor.exclude, "app.*") : descriptor.exclude,
34505
34825
  scope: resolveStyleEntryScope(descriptor, posixOutput, normalizedRoot)
34506
34826
  }, absolutePath, posixOutput, normalizedRoot, options.warningPrefix, dedupe, normalized);
34507
34827
  }
@@ -34513,14 +34833,16 @@ function normalizeSubPackageStyleEntries(styles, subPackage, configService) {
34513
34833
  if (!root) return;
34514
34834
  return normalizeStyleEntries(styles, root, configService, {
34515
34835
  warningPrefix: `[分包] 分包 ${root} `,
34516
- appendDefaultEntries: true
34836
+ appendDefaultEntries: true,
34837
+ excludeRootAppByDefault: false
34517
34838
  });
34518
34839
  }
34519
34840
  function normalizeMainPackageStyleEntries(styles, configService) {
34520
34841
  if (styles === void 0) return;
34521
34842
  return normalizeStyleEntries(styles, "", configService, {
34522
34843
  warningPrefix: "[样式] 主包 ",
34523
- appendDefaultEntries: false
34844
+ appendDefaultEntries: false,
34845
+ excludeRootAppByDefault: true
34524
34846
  });
34525
34847
  }
34526
34848
  //#endregion
@@ -34551,9 +34873,11 @@ function loadSubPackages(ctx) {
34551
34873
  const normalizedRoot = subPackage.root ? normalizeRoot(subPackage.root) : void 0;
34552
34874
  const subPackageConfig = normalizedRoot ? configService.weappViteConfig?.subPackages?.[normalizedRoot] : void 0;
34553
34875
  const npmSubPackageConfig = normalizedRoot ? configService.weappViteConfig?.npm?.subPackages?.[normalizedRoot] : void 0;
34876
+ const independent = subPackage.independent ?? subPackageConfig?.independent;
34554
34877
  const resolvedSubPackage = {
34555
34878
  ...subPackage,
34556
34879
  ...normalizedRoot ? { root: normalizedRoot } : {},
34880
+ ...independent === void 0 ? {} : { independent },
34557
34881
  dependencies: npmSubPackageConfig?.dependencies,
34558
34882
  inlineConfig: subPackageConfig?.inlineConfig
34559
34883
  };
@@ -34566,7 +34890,7 @@ function loadSubPackages(ctx) {
34566
34890
  meta.watchSharedStyles = subPackageConfig?.watchSharedStyles ?? true;
34567
34891
  if (normalizedRoot) {
34568
34892
  subPackageMap.set(normalizedRoot, meta);
34569
- if (subPackage.independent) {
34893
+ if (resolvedSubPackage.independent) {
34570
34894
  independentSubPackageMap.set(normalizedRoot, meta);
34571
34895
  if (scanState.isDirty) independentDirtyRoots.add(normalizedRoot);
34572
34896
  }