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 +21 -0
- package/dist/auto-routes.mjs +1 -1
- package/dist/cli.mjs +124 -24
- package/dist/compatibility.d.mts +2 -0
- package/dist/compatibility.mjs +2 -0
- package/dist/{config-B1H1OqnR.d.mts → config-6l-p3o-C.d.mts} +39 -11
- package/dist/config.d.mts +3 -2
- package/dist/{createContext-Ryo4nfbU.mjs → createContext-PBWMhrli.mjs} +646 -108
- package/dist/docs/README.md +21 -0
- package/dist/docs/ai-workflows.md +2 -0
- package/dist/docs/getting-started.md +1 -1
- package/dist/docs/i18n.md +44 -0
- package/dist/docs/index.md +7 -5
- package/dist/docs/testing.md +3 -1
- package/dist/docs/uni-app-component-libraries.md +4 -4
- package/dist/docs/vue-sfc.md +43 -0
- package/dist/docs/weapp-config.md +100 -1
- package/dist/docs/wevu-authoring.md +8 -0
- package/dist/eslint.d.mts +2 -0
- package/dist/eslint.mjs +2 -0
- package/dist/{file-CWbsTVPm.mjs → file-D0n-Q1ra.mjs} +1 -1
- package/dist/file-DPQbjCzZ.mjs +2 -0
- package/dist/getInstance-DxCSOpxw.mjs +2 -0
- package/dist/i18n.d.mts +9 -0
- package/dist/i18n.mjs +15 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +1 -1
- package/dist/json.d.mts +1 -1
- package/dist/mcp.d.mts +1 -1
- package/dist/test.mjs +1 -1
- package/dist/types-CgZn5X6j.d.mts +12 -0
- package/dist/types.d.mts +3 -2
- package/package.json +30 -16
- package/dist/file-BjrPjC70.mjs +0 -2
- package/dist/getInstance-CJAXp9db.mjs +0 -2
|
@@ -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-
|
|
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
|
|
@@ -192,7 +193,11 @@ function normalizeViteId(id, options) {
|
|
|
192
193
|
if (stripQuery) clean = clean.split("?", 1)[0];
|
|
193
194
|
if (fileProtocolToPathEnabled && clean.startsWith("file://")) try {
|
|
194
195
|
clean = fileURLToPath(clean);
|
|
195
|
-
} catch {
|
|
196
|
+
} catch {
|
|
197
|
+
try {
|
|
198
|
+
clean = decodeURIComponent(new URL(clean).pathname);
|
|
199
|
+
} catch {}
|
|
200
|
+
}
|
|
196
201
|
if (stripAtFsPrefix) clean = stripViteAtFsPrefix(clean);
|
|
197
202
|
if (stripLeadingNullByte && clean.startsWith("\0")) clean = clean.slice(1);
|
|
198
203
|
if (clean.includes("\\")) clean = clean.replace(BACKSLASH_RE$1, "/");
|
|
@@ -5311,13 +5316,22 @@ async function loadViteConfigFile(configEnv, configFile, configRoot, configFileD
|
|
|
5311
5316
|
}
|
|
5312
5317
|
//#endregion
|
|
5313
5318
|
//#region src/utils/preloadScan.ts
|
|
5314
|
-
const
|
|
5319
|
+
const HOST_ROUTER_METHODS = /* @__PURE__ */ new Set([
|
|
5315
5320
|
"navigateTo",
|
|
5316
5321
|
"redirectTo",
|
|
5317
5322
|
"reLaunch",
|
|
5318
|
-
"switchTab"
|
|
5319
|
-
|
|
5320
|
-
|
|
5323
|
+
"switchTab"
|
|
5324
|
+
]);
|
|
5325
|
+
const ROUTER_METHODS = /* @__PURE__ */ new Set(["push", "replace"]);
|
|
5326
|
+
const ROUTER_MODULES = /* @__PURE__ */ new Set([
|
|
5327
|
+
"vue-router",
|
|
5328
|
+
"wevu",
|
|
5329
|
+
"wevu/router"
|
|
5330
|
+
]);
|
|
5331
|
+
const ROUTER_FACTORY_METHODS = /* @__PURE__ */ new Map([
|
|
5332
|
+
["createRouter", ROUTER_METHODS],
|
|
5333
|
+
["useNativeRouter", HOST_ROUTER_METHODS],
|
|
5334
|
+
["useRouter", ROUTER_METHODS]
|
|
5321
5335
|
]);
|
|
5322
5336
|
const TEMPLATE_NAVIGATOR_RE = /<navigator(?=\s|>)[^>]*?\surl\s*=\s*(["'])([^"'{}\s]+)\1/gi;
|
|
5323
5337
|
function normalizePagePath$1(value) {
|
|
@@ -5346,14 +5360,72 @@ function getRouteFromObject(argument) {
|
|
|
5346
5360
|
if (value) return value;
|
|
5347
5361
|
}
|
|
5348
5362
|
}
|
|
5363
|
+
function getIdentifierName(node) {
|
|
5364
|
+
return node?.type === "Identifier" ? node.name : void 0;
|
|
5365
|
+
}
|
|
5366
|
+
function collectRouterBindings(ast) {
|
|
5367
|
+
const importedFactories = /* @__PURE__ */ new Map();
|
|
5368
|
+
const routerObjects = /* @__PURE__ */ new Map();
|
|
5369
|
+
const routerFunctions = /* @__PURE__ */ new Map();
|
|
5370
|
+
traverse(ast, { ImportDeclaration(importPath) {
|
|
5371
|
+
if (!ROUTER_MODULES.has(importPath.node.source?.value)) return;
|
|
5372
|
+
for (const specifier of importPath.node.specifiers ?? []) {
|
|
5373
|
+
if (specifier.type !== "ImportSpecifier") continue;
|
|
5374
|
+
const imported = getIdentifierName(specifier.imported) ?? getStaticString(specifier.imported);
|
|
5375
|
+
const local = getIdentifierName(specifier.local);
|
|
5376
|
+
const methods = imported ? ROUTER_FACTORY_METHODS.get(imported) : void 0;
|
|
5377
|
+
const binding = local ? importPath.scope.getBinding(local) : void 0;
|
|
5378
|
+
if (methods && binding) importedFactories.set(binding, methods);
|
|
5379
|
+
}
|
|
5380
|
+
} });
|
|
5381
|
+
traverse(ast, { VariableDeclarator(declaratorPath) {
|
|
5382
|
+
const init = declaratorPath.node.init;
|
|
5383
|
+
const factory = init?.type === "CallExpression" ? getIdentifierName(init.callee) : void 0;
|
|
5384
|
+
if (!factory) return;
|
|
5385
|
+
const factoryBinding = declaratorPath.scope.getBinding(factory);
|
|
5386
|
+
const methods = factoryBinding ? importedFactories.get(factoryBinding) : ROUTER_FACTORY_METHODS.get(factory);
|
|
5387
|
+
if (!methods) return;
|
|
5388
|
+
const id = declaratorPath.node.id;
|
|
5389
|
+
const objectName = getIdentifierName(id);
|
|
5390
|
+
if (objectName) {
|
|
5391
|
+
const binding = declaratorPath.scope.getBinding(objectName);
|
|
5392
|
+
if (binding?.constant) routerObjects.set(binding, methods);
|
|
5393
|
+
return;
|
|
5394
|
+
}
|
|
5395
|
+
if (id?.type !== "ObjectPattern") return;
|
|
5396
|
+
for (const property of id.properties ?? []) {
|
|
5397
|
+
if (property.type !== "ObjectProperty" && property.type !== "Property") continue;
|
|
5398
|
+
const importedMethod = getPropertyName(property.key);
|
|
5399
|
+
const local = getIdentifierName(property.value);
|
|
5400
|
+
const binding = local ? declaratorPath.scope.getBinding(local) : void 0;
|
|
5401
|
+
if (importedMethod && methods.has(importedMethod) && binding?.constant) routerFunctions.set(binding, importedMethod);
|
|
5402
|
+
}
|
|
5403
|
+
} });
|
|
5404
|
+
return {
|
|
5405
|
+
routerFunctions,
|
|
5406
|
+
routerObjects
|
|
5407
|
+
};
|
|
5408
|
+
}
|
|
5409
|
+
function getNavigationMethod(callPath, bindings) {
|
|
5410
|
+
const callee = callPath.node.callee;
|
|
5411
|
+
const directName = getIdentifierName(callee);
|
|
5412
|
+
const directMethod = directName ? bindings.routerFunctions.get(callPath.scope.getBinding(directName)) : void 0;
|
|
5413
|
+
if (directMethod) return directMethod;
|
|
5414
|
+
if (callee?.type !== "MemberExpression" && callee?.type !== "OptionalMemberExpression") return;
|
|
5415
|
+
const objectName = getIdentifierName(callee.object);
|
|
5416
|
+
const method = getPropertyName(callee.property);
|
|
5417
|
+
if (objectName === "wx" && !callPath.scope.getBinding("wx") && method && HOST_ROUTER_METHODS.has(method)) return method;
|
|
5418
|
+
if (objectName && method) {
|
|
5419
|
+
if (bindings.routerObjects.get(callPath.scope.getBinding(objectName))?.has(method)) return method;
|
|
5420
|
+
}
|
|
5421
|
+
}
|
|
5349
5422
|
function collectScriptTargets(source, sourcePage) {
|
|
5350
5423
|
const targets = [];
|
|
5351
5424
|
try {
|
|
5352
5425
|
const ast = parseJsLike(source);
|
|
5426
|
+
const bindings = collectRouterBindings(ast);
|
|
5353
5427
|
traverse(ast, { CallExpression(callPath) {
|
|
5354
|
-
|
|
5355
|
-
const method = callee?.type === "Identifier" ? callee.name : callee?.type === "MemberExpression" ? getPropertyName(callee.property) : void 0;
|
|
5356
|
-
if (!ROUTER_METHODS.has(method)) return;
|
|
5428
|
+
if (!getNavigationMethod(callPath, bindings)) return;
|
|
5357
5429
|
const argument = callPath.node.arguments?.[0];
|
|
5358
5430
|
const target = getStaticString(argument) ?? getRouteFromObject(argument);
|
|
5359
5431
|
if (target) targets.push(normalizeStaticTarget(target, sourcePage));
|
|
@@ -5458,7 +5530,8 @@ function collectSubPackages(appJson) {
|
|
|
5458
5530
|
const root = normalizePackageRoot(item.root);
|
|
5459
5531
|
return (Array.isArray(item.pages) ? item.pages.filter((page) => typeof page === "string" && page.trim().length > 0) : []).map((page) => ({
|
|
5460
5532
|
route: normalizePagePath(path.posix.join(root, page)),
|
|
5461
|
-
packageRoot: root
|
|
5533
|
+
packageRoot: root,
|
|
5534
|
+
...item.independent === true ? { independent: true } : {}
|
|
5462
5535
|
}));
|
|
5463
5536
|
});
|
|
5464
5537
|
}
|
|
@@ -5469,6 +5542,17 @@ function findPreloadRuleKey(page, preloadRule) {
|
|
|
5469
5542
|
const candidates = pageCandidates(page);
|
|
5470
5543
|
return Object.keys(preloadRule).find((candidate) => candidates.includes(normalizePagePath(candidate)));
|
|
5471
5544
|
}
|
|
5545
|
+
function resolvePreloadPackageIdentifier(value, appJson) {
|
|
5546
|
+
const normalized = value === "__APP__" ? value : normalizePackageRoot(value);
|
|
5547
|
+
if (!normalized || normalized === "__APP__") return normalized || void 0;
|
|
5548
|
+
const source = Array.isArray(appJson.subPackages) ? appJson.subPackages : Array.isArray(appJson.subpackages) ? appJson.subpackages : [];
|
|
5549
|
+
for (const item of source) {
|
|
5550
|
+
if (!isObject(item) || typeof item.root !== "string") continue;
|
|
5551
|
+
const root = normalizePackageRoot(item.root);
|
|
5552
|
+
if (root === normalized || typeof item.name === "string" && item.name === value) return root;
|
|
5553
|
+
}
|
|
5554
|
+
return normalized;
|
|
5555
|
+
}
|
|
5472
5556
|
function cloneRule(rule) {
|
|
5473
5557
|
if (!isObject(rule)) return rule;
|
|
5474
5558
|
const packages = Array.isArray(rule.packages) ? rule.packages.filter((item) => typeof item === "string") : [];
|
|
@@ -5495,13 +5579,15 @@ function applyPreloadRulesToAppJson(appJson, routeRules, platform) {
|
|
|
5495
5579
|
}
|
|
5496
5580
|
function suggestPreloadRules(appJson, pageSources) {
|
|
5497
5581
|
const pages = collectPreloadPages(appJson);
|
|
5498
|
-
const
|
|
5582
|
+
const pageByRoute = new Map(pages.map((page) => [page.route, page]));
|
|
5499
5583
|
const suggestions = [];
|
|
5500
5584
|
const uncovered = /* @__PURE__ */ new Set();
|
|
5501
5585
|
for (const page of pages) {
|
|
5502
5586
|
const source = pageSources.get(page.route);
|
|
5503
5587
|
for (const kind of ["template", "script"]) for (const target of collectStaticRouteTargets(source?.[kind] ?? "", kind, page.route)) {
|
|
5504
|
-
const
|
|
5588
|
+
const targetPage = pageByRoute.get(target);
|
|
5589
|
+
if (!targetPage) continue;
|
|
5590
|
+
const packageRoot = targetPage.packageRoot ?? (page.independent ? "__APP__" : void 0);
|
|
5505
5591
|
if (!packageRoot || packageRoot === page.packageRoot) continue;
|
|
5506
5592
|
const suggestion = {
|
|
5507
5593
|
page: page.route,
|
|
@@ -9160,7 +9246,10 @@ function createRuntimeState() {
|
|
|
9160
9246
|
build: {
|
|
9161
9247
|
queue: new PQueue({ autoStart: false }),
|
|
9162
9248
|
npmBuilt: false,
|
|
9163
|
-
independent: {
|
|
9249
|
+
independent: {
|
|
9250
|
+
outputs: /* @__PURE__ */ new Map(),
|
|
9251
|
+
pendingOutputs: []
|
|
9252
|
+
},
|
|
9164
9253
|
output: {
|
|
9165
9254
|
emittedSource: /* @__PURE__ */ new Map(),
|
|
9166
9255
|
wevuInternalRuntimeFileName: void 0,
|
|
@@ -9223,6 +9312,7 @@ function createRuntimeState() {
|
|
|
9223
9312
|
emittedCode: /* @__PURE__ */ new Map()
|
|
9224
9313
|
},
|
|
9225
9314
|
scan: {
|
|
9315
|
+
mainPackageStyleEntries: void 0,
|
|
9226
9316
|
subPackageMap: /* @__PURE__ */ new Map(),
|
|
9227
9317
|
independentSubPackageMap: /* @__PURE__ */ new Map(),
|
|
9228
9318
|
warnedMessages: /* @__PURE__ */ new Set(),
|
|
@@ -9292,6 +9382,7 @@ function resetRuntimeStateForFreshBuild(runtimeState) {
|
|
|
9292
9382
|
wxml.cache.signatureMap.clear();
|
|
9293
9383
|
wxml.emittedCode.clear();
|
|
9294
9384
|
const scan = runtimeState.scan;
|
|
9385
|
+
scan.mainPackageStyleEntries = void 0;
|
|
9295
9386
|
scan.subPackageMap.clear();
|
|
9296
9387
|
scan.independentSubPackageMap.clear();
|
|
9297
9388
|
scan.warnedMessages.clear();
|
|
@@ -10766,6 +10857,83 @@ function createAdvancedChunkNameResolver(options) {
|
|
|
10766
10857
|
};
|
|
10767
10858
|
}
|
|
10768
10859
|
//#endregion
|
|
10860
|
+
//#region src/runtime/preserveModules.ts
|
|
10861
|
+
const PRESERVED_MODULE_GROUP_PRIORITY = 100;
|
|
10862
|
+
function createPatternMatcher(pattern) {
|
|
10863
|
+
if (typeof pattern === "string") {
|
|
10864
|
+
const matcher = picomatch(pattern, { dot: true });
|
|
10865
|
+
return (value) => matcher(value);
|
|
10866
|
+
}
|
|
10867
|
+
if (isRegexp(pattern)) return (value) => {
|
|
10868
|
+
pattern.lastIndex = 0;
|
|
10869
|
+
return pattern.test(value);
|
|
10870
|
+
};
|
|
10871
|
+
}
|
|
10872
|
+
function createPreserveModuleMatcher(patterns) {
|
|
10873
|
+
const matchers = patterns?.map((pattern) => createPatternMatcher(pattern)).filter((matcher) => typeof matcher === "function");
|
|
10874
|
+
if (!matchers?.length) return;
|
|
10875
|
+
return (relativeId, absoluteId) => {
|
|
10876
|
+
return matchers.some((matcher) => matcher(relativeId) || matcher(absoluteId));
|
|
10877
|
+
};
|
|
10878
|
+
}
|
|
10879
|
+
function normalizePreservedSourceId(id) {
|
|
10880
|
+
return normalizeViteId(id, {
|
|
10881
|
+
stripQuery: true,
|
|
10882
|
+
fileProtocolToPath: true,
|
|
10883
|
+
stripAtFsPrefix: true,
|
|
10884
|
+
stripLeadingNullByte: true
|
|
10885
|
+
});
|
|
10886
|
+
}
|
|
10887
|
+
function normalizePreserveModulesRolldownOptions(configService, rolldownOptions) {
|
|
10888
|
+
if (configService.weappViteConfig?.chunks?.preserveModules?.length && (rolldownOptions.preserveEntrySignatures === void 0 || rolldownOptions.preserveEntrySignatures === "exports-only")) rolldownOptions.preserveEntrySignatures = "allow-extension";
|
|
10889
|
+
return rolldownOptions;
|
|
10890
|
+
}
|
|
10891
|
+
function resolvePreservedModuleName(options) {
|
|
10892
|
+
const { configService, ctx, getSubPackageRoots, id } = options;
|
|
10893
|
+
if (parseSidecarSourceRequest(id)) return;
|
|
10894
|
+
const absoluteId = normalizePreservedSourceId(id);
|
|
10895
|
+
if (!path.isAbsolute(absoluteId) || !isPathInside(configService.absoluteSrcRoot, absoluteId)) return;
|
|
10896
|
+
const moduleInfo = ctx.getModuleInfo(id);
|
|
10897
|
+
if (moduleInfo?.importers?.some((importer) => {
|
|
10898
|
+
return parseLogicalEntryId(importer)?.sourceId === absoluteId;
|
|
10899
|
+
})) return;
|
|
10900
|
+
const relativeId = normalizeRelativePath$1(path.relative(configService.absoluteSrcRoot, absoluteId));
|
|
10901
|
+
if (!relativeId || relativeId.startsWith("..")) return;
|
|
10902
|
+
const subPackageRoots = Array.from(getSubPackageRoots());
|
|
10903
|
+
const moduleRoot = resolveSubPackagePrefix(relativeId, subPackageRoots);
|
|
10904
|
+
if (moduleRoot) assertModuleScopedToRoot({
|
|
10905
|
+
moduleInfo,
|
|
10906
|
+
moduleRoot,
|
|
10907
|
+
relativeAbsoluteSrcRoot: configService.relativeAbsoluteSrcRoot,
|
|
10908
|
+
subPackageRoots,
|
|
10909
|
+
moduleId: id
|
|
10910
|
+
});
|
|
10911
|
+
const name = removeExtensionDeep(relativeId);
|
|
10912
|
+
return name && name !== "." ? name : void 0;
|
|
10913
|
+
}
|
|
10914
|
+
function createPreserveModulesGroup(configService, getSubPackageRoots) {
|
|
10915
|
+
const matches = createPreserveModuleMatcher(configService.weappViteConfig?.chunks?.preserveModules);
|
|
10916
|
+
if (!matches) return;
|
|
10917
|
+
return {
|
|
10918
|
+
name: (id, ctx) => resolvePreservedModuleName({
|
|
10919
|
+
configService,
|
|
10920
|
+
ctx,
|
|
10921
|
+
getSubPackageRoots,
|
|
10922
|
+
id
|
|
10923
|
+
}),
|
|
10924
|
+
test: (id) => {
|
|
10925
|
+
const absoluteId = normalizePreservedSourceId(id);
|
|
10926
|
+
const relativeId = configService.relativeAbsoluteSrcRoot(absoluteId);
|
|
10927
|
+
return matches(relativeId, absoluteId);
|
|
10928
|
+
},
|
|
10929
|
+
priority: PRESERVED_MODULE_GROUP_PRIORITY,
|
|
10930
|
+
minShareCount: 1,
|
|
10931
|
+
minSize: 0,
|
|
10932
|
+
minModuleSize: 0,
|
|
10933
|
+
includeDependenciesRecursively: false
|
|
10934
|
+
};
|
|
10935
|
+
}
|
|
10936
|
+
//#endregion
|
|
10769
10937
|
//#region src/runtime/wevuModules.ts
|
|
10770
10938
|
const WEVU_RUNTIME_MODULE_IDS = [
|
|
10771
10939
|
"wevu",
|
|
@@ -11077,15 +11245,20 @@ function createSharedBuildResolver(configService, getSubPackageRoots) {
|
|
|
11077
11245
|
return { resolveAdvancedChunkName: resolveSharedBuildChunkName };
|
|
11078
11246
|
}
|
|
11079
11247
|
function createSharedBuildOutput(configService, getSubPackageRoots, options = {}) {
|
|
11248
|
+
const preserveModulesGroup = createPreserveModulesGroup(configService, getSubPackageRoots);
|
|
11080
11249
|
const { resolveAdvancedChunkName } = createSharedBuildResolver(configService, getSubPackageRoots);
|
|
11081
11250
|
return {
|
|
11082
|
-
codeSplitting: { groups: [
|
|
11083
|
-
|
|
11084
|
-
|
|
11085
|
-
|
|
11086
|
-
|
|
11087
|
-
|
|
11088
|
-
|
|
11251
|
+
codeSplitting: { groups: [
|
|
11252
|
+
...preserveModulesGroup ? [preserveModulesGroup] : [],
|
|
11253
|
+
...configService.isDev ? [{
|
|
11254
|
+
test: isStableHashedDistChunkModule,
|
|
11255
|
+
minShareCount: 1,
|
|
11256
|
+
minSize: 0,
|
|
11257
|
+
minModuleSize: 0,
|
|
11258
|
+
name: (id) => resolveStableHashedDistChunkName({ facadeModuleId: id })
|
|
11259
|
+
}] : [],
|
|
11260
|
+
{ name: (id, ctx) => resolveAdvancedChunkName(id, ctx) }
|
|
11261
|
+
] },
|
|
11089
11262
|
minifyInternalExports: false,
|
|
11090
11263
|
chunkFileNames: (chunk) => {
|
|
11091
11264
|
if (isRequestGlobalsRuntimeChunk(chunk)) return REQUEST_GLOBAL_RUNTIME_CHUNK_FILE_BASENAME;
|
|
@@ -11100,7 +11273,12 @@ function createSharedBuildOutput(configService, getSubPackageRoots, options = {}
|
|
|
11100
11273
|
};
|
|
11101
11274
|
}
|
|
11102
11275
|
function createSharedBuildConfig(configService, scanService) {
|
|
11103
|
-
|
|
11276
|
+
const output = createSharedBuildOutput(configService, () => scanService.subPackageMap.keys());
|
|
11277
|
+
const preserveEntrySignatures = configService.weappViteConfig?.chunks?.preserveModules?.length ? "allow-extension" : void 0;
|
|
11278
|
+
return { build: { rolldownOptions: {
|
|
11279
|
+
...preserveEntrySignatures ? { preserveEntrySignatures } : {},
|
|
11280
|
+
output
|
|
11281
|
+
} } };
|
|
11104
11282
|
}
|
|
11105
11283
|
//#endregion
|
|
11106
11284
|
//#region src/runtime/statefulHmr/runtimeSource.ts
|
|
@@ -11814,7 +11992,7 @@ const EVENT_NAMES = {
|
|
|
11814
11992
|
onTapCapture: "capture-bind:tap"
|
|
11815
11993
|
};
|
|
11816
11994
|
const EVENT_PROP_RE = /^on[A-Z]/;
|
|
11817
|
-
const IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
|
|
11995
|
+
const IDENTIFIER_RE$1 = /^[A-Z_$][\w$]*$/i;
|
|
11818
11996
|
function escapeAttribute(value) {
|
|
11819
11997
|
return value.replaceAll("&", "&").replaceAll("\"", """).replaceAll("<", "<");
|
|
11820
11998
|
}
|
|
@@ -11869,7 +12047,7 @@ function resolveNativeEvent(name) {
|
|
|
11869
12047
|
return `${capture ? "capture-bind" : "bind"}:${toKebabCase$1(eventName)}`;
|
|
11870
12048
|
}
|
|
11871
12049
|
function renderBindingExpression(slot, name) {
|
|
11872
|
-
return IDENTIFIER_RE.test(name) ? `slots.${slot}.${name}` : `slots.${slot}['${name}']`;
|
|
12050
|
+
return IDENTIFIER_RE$1.test(name) ? `slots.${slot}.${name}` : `slots.${slot}['${name}']`;
|
|
11873
12051
|
}
|
|
11874
12052
|
function compileAttributes(element, slot, bindingFields, tagKind) {
|
|
11875
12053
|
const output = [];
|
|
@@ -14403,6 +14581,8 @@ function parseWxml(options) {
|
|
|
14403
14581
|
const conditionalStack = [];
|
|
14404
14582
|
const commentTokens = [];
|
|
14405
14583
|
const inlineWxsTokens = [];
|
|
14584
|
+
const templateTokens = [];
|
|
14585
|
+
const scriptModules = [];
|
|
14406
14586
|
const scriptModuleTagTokens = [];
|
|
14407
14587
|
const wxsImportNormalizeTokens = [];
|
|
14408
14588
|
const removeWxsLangAttrTokens = [];
|
|
@@ -14433,6 +14613,11 @@ function parseWxml(options) {
|
|
|
14433
14613
|
},
|
|
14434
14614
|
onattribute(name, value, quote) {
|
|
14435
14615
|
attrs[name] = value;
|
|
14616
|
+
if (!currentTagName || !isScriptModuleTagName(currentTagName)) templateTokens.push({
|
|
14617
|
+
start: parser.startIndex,
|
|
14618
|
+
end: parser.endIndex + 1,
|
|
14619
|
+
value
|
|
14620
|
+
});
|
|
14436
14621
|
if (importAttrs && currentTagName) {
|
|
14437
14622
|
for (const attrName of importAttrs) if (attrName === name) {
|
|
14438
14623
|
deps.push({
|
|
@@ -14492,6 +14677,12 @@ function parseWxml(options) {
|
|
|
14492
14677
|
value
|
|
14493
14678
|
});
|
|
14494
14679
|
},
|
|
14680
|
+
onopentag(name, attributes) {
|
|
14681
|
+
if (isScriptModuleTagName(name)) scriptModules.push({
|
|
14682
|
+
attrs: attributes,
|
|
14683
|
+
tagName: name
|
|
14684
|
+
});
|
|
14685
|
+
},
|
|
14495
14686
|
onclosetag(name) {
|
|
14496
14687
|
currentTagName = tagStack.pop();
|
|
14497
14688
|
if (currentTagName) {
|
|
@@ -14539,6 +14730,11 @@ function parseWxml(options) {
|
|
|
14539
14730
|
end: parser.endIndex,
|
|
14540
14731
|
value: data
|
|
14541
14732
|
});
|
|
14733
|
+
else templateTokens.push({
|
|
14734
|
+
start: parser.startIndex,
|
|
14735
|
+
end: parser.endIndex + 1,
|
|
14736
|
+
value: data
|
|
14737
|
+
});
|
|
14542
14738
|
},
|
|
14543
14739
|
oncomment(data) {
|
|
14544
14740
|
let match = COMMENT_IFDEF_RE.exec(data);
|
|
@@ -14573,6 +14769,8 @@ function parseWxml(options) {
|
|
|
14573
14769
|
removalRanges,
|
|
14574
14770
|
commentTokens,
|
|
14575
14771
|
inlineWxsTokens,
|
|
14772
|
+
scriptModules,
|
|
14773
|
+
templateTokens,
|
|
14576
14774
|
wxsImportNormalizeTokens,
|
|
14577
14775
|
removeWxsLangAttrTokens,
|
|
14578
14776
|
templateImportNormalizeTokens,
|
|
@@ -15328,6 +15526,7 @@ function createIndependentBuilder(configService, buildState) {
|
|
|
15328
15526
|
mode: configService.mode,
|
|
15329
15527
|
configFile: configService.configFilePath,
|
|
15330
15528
|
cliPlatform: configService.platform,
|
|
15529
|
+
inlineConfig: { weapp: { platform: configService.platform } },
|
|
15331
15530
|
projectConfigPath: configService.projectConfigPath
|
|
15332
15531
|
});
|
|
15333
15532
|
const isolatedConfigService = isolatedCtx.configService;
|
|
@@ -17614,7 +17813,8 @@ function configureBuildAndPlugins(options) {
|
|
|
17614
17813
|
const rdTransform = rdOptions.transform ?? {};
|
|
17615
17814
|
if (!Object.prototype.hasOwnProperty.call(rdTransform, "tsconfig")) rdTransform.tsconfig = false;
|
|
17616
17815
|
rdOptions.transform = rdTransform;
|
|
17617
|
-
rdOptions.preserveEntrySignatures
|
|
17816
|
+
if (config.weapp?.chunks?.preserveModules?.length && (rdOptions.preserveEntrySignatures === void 0 || rdOptions.preserveEntrySignatures === "exports-only")) rdOptions.preserveEntrySignatures = "allow-extension";
|
|
17817
|
+
else rdOptions.preserveEntrySignatures ??= "exports-only";
|
|
17618
17818
|
if (Array.isArray(rdOptions.output)) rdOptions.output = rdOptions.output.map((output) => ({
|
|
17619
17819
|
...output,
|
|
17620
17820
|
format: jsFormat
|
|
@@ -17938,8 +18138,9 @@ function createLoadConfig(options) {
|
|
|
17938
18138
|
}
|
|
17939
18139
|
const loadedConfig = loaded?.config ?? {};
|
|
17940
18140
|
let weappLoaded;
|
|
18141
|
+
const reuseLoadedWeappConfig = shouldReuseLoadedWeappConfig(weappConfigFilePath, loaded?.path);
|
|
17941
18142
|
if (weappConfigFilePath) {
|
|
17942
|
-
if (
|
|
18143
|
+
if (reuseLoadedWeappConfig) weappLoaded = loaded;
|
|
17943
18144
|
else try {
|
|
17944
18145
|
weappLoaded = await loadConfigFileWithFallback({
|
|
17945
18146
|
command: isDev ? "serve" : "build",
|
|
@@ -17955,7 +18156,7 @@ function createLoadConfig(options) {
|
|
|
17955
18156
|
throw error;
|
|
17956
18157
|
}
|
|
17957
18158
|
}
|
|
17958
|
-
const mergedLoadedConfig = weappLoaded?.config ? defu(weappLoaded.config, loadedConfig) : loadedConfig;
|
|
18159
|
+
const mergedLoadedConfig = weappLoaded?.config ? reuseLoadedWeappConfig ? loadedConfig : defu(weappLoaded.config, loadedConfig) : loadedConfig;
|
|
17959
18160
|
const config = defu(inlineConfig, {
|
|
17960
18161
|
mode,
|
|
17961
18162
|
configFile: false
|
|
@@ -24995,28 +25196,6 @@ function refreshPartialSharedChunkImporters(bundle, state, entryIds) {
|
|
|
24995
25196
|
appendSharedChunkImporters(bundle, state, refreshedEntryIds, previousImporters, previousDependencies);
|
|
24996
25197
|
}
|
|
24997
25198
|
//#endregion
|
|
24998
|
-
//#region src/plugins/core/helpers/independent.ts
|
|
24999
|
-
async function flushIndependentBuilds(state) {
|
|
25000
|
-
const { subPackageMeta, pendingIndependentBuilds } = state;
|
|
25001
|
-
if (subPackageMeta || pendingIndependentBuilds.length === 0) return;
|
|
25002
|
-
const outputs = await Promise.all(pendingIndependentBuilds);
|
|
25003
|
-
for (const { rollup } of outputs) {
|
|
25004
|
-
const bundleOutputs = Array.isArray(rollup?.output) ? rollup.output : [];
|
|
25005
|
-
for (const output of bundleOutputs) if (output.type === "chunk") this.emitFile({
|
|
25006
|
-
type: "asset",
|
|
25007
|
-
source: output.code,
|
|
25008
|
-
fileName: output.fileName,
|
|
25009
|
-
name: output.name
|
|
25010
|
-
});
|
|
25011
|
-
else this.emitFile({
|
|
25012
|
-
type: "asset",
|
|
25013
|
-
source: output.source,
|
|
25014
|
-
fileName: output.fileName
|
|
25015
|
-
});
|
|
25016
|
-
}
|
|
25017
|
-
state.pendingIndependentBuilds = [];
|
|
25018
|
-
}
|
|
25019
|
-
//#endregion
|
|
25020
25199
|
//#region src/runtime/config/internal/injectRequestGlobals.ts
|
|
25021
25200
|
const FULL_REQUEST_GLOBAL_TARGETS = [
|
|
25022
25201
|
"fetch",
|
|
@@ -25743,9 +25922,11 @@ function invalidateSharedStyleCache() {
|
|
|
25743
25922
|
const styleMatcherCache = /* @__PURE__ */ new WeakMap();
|
|
25744
25923
|
function collectSharedStyleEntries(ctx, configService) {
|
|
25745
25924
|
const map = /* @__PURE__ */ new Map();
|
|
25925
|
+
const mainPackageEntries = ctx.scanService?.mainPackageStyleEntries;
|
|
25926
|
+
const currentRoot = configService.currentSubPackageRoot;
|
|
25927
|
+
if (!currentRoot && mainPackageEntries?.length) map.set("", mainPackageEntries);
|
|
25746
25928
|
const registry = ctx.scanService?.subPackageMap;
|
|
25747
25929
|
if (!registry?.size) return map;
|
|
25748
|
-
const currentRoot = configService.currentSubPackageRoot;
|
|
25749
25930
|
for (const [root, meta] of registry.entries()) {
|
|
25750
25931
|
if (!meta.styleEntries?.length) continue;
|
|
25751
25932
|
if (currentRoot && root !== currentRoot) continue;
|
|
@@ -25794,11 +25975,14 @@ function findSharedStylesForModule(modulePath, fileName, sharedStyles) {
|
|
|
25794
25975
|
const matched = [];
|
|
25795
25976
|
for (const [root, entries] of sharedStyles.entries()) {
|
|
25796
25977
|
const normalizedRoot = normalizeRoot(root);
|
|
25797
|
-
if (!normalizedRoot) continue;
|
|
25978
|
+
if (root && !normalizedRoot) continue;
|
|
25798
25979
|
if (!isWithinRoot(sanitizedFile, normalizedRoot)) continue;
|
|
25799
25980
|
const relativeModule = relativeToRoot(sanitizedModule, normalizedRoot);
|
|
25800
25981
|
const relativeFile = relativeToRoot(sanitizedFile, normalizedRoot);
|
|
25801
|
-
for (const entry of entries)
|
|
25982
|
+
for (const entry of entries) {
|
|
25983
|
+
if (entry.inject === false) continue;
|
|
25984
|
+
if (matchesStyleEntry(entry, relativeModule, relativeFile)) matched.push(entry);
|
|
25985
|
+
}
|
|
25802
25986
|
}
|
|
25803
25987
|
return matched;
|
|
25804
25988
|
}
|
|
@@ -26074,9 +26258,10 @@ async function handleBundleEntry(ctx, bundle, bundleKey, asset, configService, s
|
|
|
26074
26258
|
const cssWithImports = injectSharedStyleImportsCached(processedCss, owner, fileName, sharedStyles, configService, sharedStyleImportCache);
|
|
26075
26259
|
emitCssAssetIfChanged(ctx, this, bundle, fileName, cssWithImports);
|
|
26076
26260
|
emitted.add(normalizedFileName);
|
|
26261
|
+
return normalizedFileName;
|
|
26077
26262
|
};
|
|
26078
|
-
const isFinalStyleAsset = bundleKey.endsWith(`.${configService.outputExtensions.wxss}`);
|
|
26079
26263
|
const isCssAsset = bundleKey.endsWith(".css");
|
|
26264
|
+
const isFinalStyleAsset = bundleKey.endsWith(`.${configService.outputExtensions.wxss}`) && (!isCssAsset || path.posix.basename(bundleKey, ".css") === "app");
|
|
26080
26265
|
const isSourceStyleAssetKey = isSourceStyleAsset(bundleKey);
|
|
26081
26266
|
if (isFinalStyleAsset) {
|
|
26082
26267
|
const absOriginal = resolveOriginalStylePath();
|
|
@@ -26116,10 +26301,11 @@ async function handleBundleEntry(ctx, bundle, bundleKey, asset, configService, s
|
|
|
26116
26301
|
delete bundle[bundleKey];
|
|
26117
26302
|
return;
|
|
26118
26303
|
}
|
|
26119
|
-
await Promise.all(Array.from(owners).map(async (owner) => {
|
|
26120
|
-
await emitStyleAssetForOwner(owner, resolveOriginalStylePath(), !isCssAsset);
|
|
26304
|
+
const emittedOwners = await Promise.all(Array.from(owners).map(async (owner) => {
|
|
26305
|
+
return await emitStyleAssetForOwner(owner, resolveOriginalStylePath(), !isCssAsset);
|
|
26121
26306
|
}));
|
|
26122
|
-
|
|
26307
|
+
const normalizedBundleKey = toPosixPath(bundleKey);
|
|
26308
|
+
if (!isCssAsset || !emittedOwners.includes(normalizedBundleKey)) delete bundle[bundleKey];
|
|
26123
26309
|
}
|
|
26124
26310
|
async function emitSharedStyleEntries(ctx, sharedStyles, emitted, configService, bundle, resolvedConfig) {
|
|
26125
26311
|
if (!sharedStyles.size) return;
|
|
@@ -26255,6 +26441,296 @@ function css(ctx) {
|
|
|
26255
26441
|
}];
|
|
26256
26442
|
}
|
|
26257
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
|
|
26258
26734
|
//#region src/plugins/outputFinalizer.ts
|
|
26259
26735
|
const PREPROCESSOR_STYLE_ASSET_RE = /\.(?:less|sass|scss|styl|stylus|pcss|postcss|sss)$/i;
|
|
26260
26736
|
const TEMPLATE_ASSET_RE = /\.(?:wxml|axml|swan|ttml|jxml|qml|ksml|xhsml)$/i;
|
|
@@ -26383,22 +26859,23 @@ function normalizePreprocessorStyleAssets(bundle, styleExtension, emitAsset) {
|
|
|
26383
26859
|
if (!styleExtension) return;
|
|
26384
26860
|
normalizePreprocessorStyleAssetEntries(bundle, collectOutputFinalizerAssetEntries(bundle).preprocessorStyleAssets, styleExtension, emitAsset);
|
|
26385
26861
|
}
|
|
26386
|
-
function normalizeTemplateAssetEntries(ctx, entries) {
|
|
26862
|
+
function normalizeTemplateAssetEntries(ctx, entries, subPackageMeta) {
|
|
26387
26863
|
const { configService } = ctx;
|
|
26388
|
-
for (const { output } of entries) {
|
|
26864
|
+
for (const { bundleFileName, output } of entries) {
|
|
26389
26865
|
const source = output.source;
|
|
26390
26866
|
const code = typeof source === "string" ? source : source instanceof Uint8Array ? Buffer.from(source).toString("utf8") : void 0;
|
|
26391
26867
|
if (code === void 0) continue;
|
|
26392
|
-
|
|
26393
|
-
|
|
26868
|
+
let normalized = code;
|
|
26869
|
+
if (mayNeedTemplateNormalization(code, configService?.platform)) normalized = handleWxml(scanWxml(code, { platform: configService?.platform }), {
|
|
26394
26870
|
scriptModuleExtension: configService?.outputExtensions?.wxs,
|
|
26395
26871
|
scriptModuleTag: resolveScriptModuleTagName({
|
|
26396
26872
|
platform: configService?.platform,
|
|
26397
26873
|
scriptModuleExtension: configService?.outputExtensions?.wxs
|
|
26398
26874
|
}),
|
|
26399
26875
|
templateExtension: configService?.outputExtensions?.wxml
|
|
26400
|
-
});
|
|
26401
|
-
|
|
26876
|
+
}).code;
|
|
26877
|
+
const transformed = transformI18nOutputTemplate(ctx, output.fileName || bundleFileName, normalized, subPackageMeta);
|
|
26878
|
+
if (transformed !== code) output.source = transformed;
|
|
26402
26879
|
}
|
|
26403
26880
|
}
|
|
26404
26881
|
function pruneUneventedDevHmrChunks(ctx, bundle) {
|
|
@@ -26429,7 +26906,7 @@ function pruneUnchangedDevHmrOutputs(ctx, bundle, rewriteOptions, options) {
|
|
|
26429
26906
|
cache.set(fileName, source);
|
|
26430
26907
|
}
|
|
26431
26908
|
}
|
|
26432
|
-
function createOutputFinalizerPlugin(ctx) {
|
|
26909
|
+
function createOutputFinalizerPlugin(ctx, subPackageMeta) {
|
|
26433
26910
|
const wevuRuntimeRewriteOptions = {
|
|
26434
26911
|
get runtimeFileName() {
|
|
26435
26912
|
return ctx.runtimeState?.build?.output?.wevuInternalRuntimeFileName;
|
|
@@ -26457,7 +26934,7 @@ function createOutputFinalizerPlugin(ctx) {
|
|
|
26457
26934
|
enforce: "post",
|
|
26458
26935
|
generateBundle: {
|
|
26459
26936
|
order: "post",
|
|
26460
|
-
handler(_options, bundle) {
|
|
26937
|
+
async handler(_options, bundle) {
|
|
26461
26938
|
const outputBundle = bundle;
|
|
26462
26939
|
rewriteWevuInternalRuntimeImports(bundle, wevuRuntimeRewriteOptions);
|
|
26463
26940
|
stabilizeWevuRuntimeChunkAccess(bundle);
|
|
@@ -26465,9 +26942,10 @@ function createOutputFinalizerPlugin(ctx) {
|
|
|
26465
26942
|
normalizeGraphOnlyAssets(ctx, outputBundle, (asset) => this.emitFile(asset));
|
|
26466
26943
|
const assetEntries = collectOutputFinalizerAssetEntries(outputBundle);
|
|
26467
26944
|
normalizePreprocessorStyleAssetEntries(outputBundle, assetEntries.preprocessorStyleAssets, ctx.configService.outputExtensions?.wxss, (asset) => this.emitFile(asset));
|
|
26468
|
-
normalizeTemplateAssetEntries(ctx, assetEntries.templateAssets);
|
|
26945
|
+
normalizeTemplateAssetEntries(ctx, assetEntries.templateAssets, subPackageMeta);
|
|
26469
26946
|
pruneUnchangedDevHmrOutputs(ctx, outputBundle, wevuRuntimeRewriteOptions, { runtimeRewriteDone: true });
|
|
26470
26947
|
syncOutputChunkSourceMapAssets(outputBundle);
|
|
26948
|
+
await flushIndependentOutputs(ctx, subPackageMeta, (asset) => this.emitFile(asset));
|
|
26471
26949
|
}
|
|
26472
26950
|
}
|
|
26473
26951
|
};
|
|
@@ -27970,7 +28448,6 @@ function createGenerateBundleHook(state, isPluginBuild) {
|
|
|
27970
28448
|
ctx.moduleGraphService?.bindPluginContext(this);
|
|
27971
28449
|
const rolldownBundle = bundle;
|
|
27972
28450
|
const scriptAnalysisCache = /* @__PURE__ */ new WeakMap();
|
|
27973
|
-
await flushIndependentBuilds.call(this, state);
|
|
27974
28451
|
const hasChunkOutput = pruneHmrMetadataOnlyChunks(rolldownBundle, state);
|
|
27975
28452
|
await emitCurrentStyleSidecarAsset.call(this, state, rolldownBundle);
|
|
27976
28453
|
const assetOnlyDevHmrBundle = isAssetOnlyDevHmrBundle(hasChunkOutput, state);
|
|
@@ -28593,7 +29070,6 @@ function createOptionsHook(state) {
|
|
|
28593
29070
|
const { scanService, configService, buildService } = ctx;
|
|
28594
29071
|
return async function options(options) {
|
|
28595
29072
|
if (this) ctx.moduleGraphService?.bindPluginContext(this);
|
|
28596
|
-
state.pendingIndependentBuilds = [];
|
|
28597
29073
|
state.hmrRootInputIds ??= /* @__PURE__ */ new Set();
|
|
28598
29074
|
state.hmrRootInputIds.clear();
|
|
28599
29075
|
let scannedInput;
|
|
@@ -28638,21 +29114,17 @@ function createOptionsHook(state) {
|
|
|
28638
29114
|
type: "app"
|
|
28639
29115
|
}]));
|
|
28640
29116
|
else {
|
|
29117
|
+
const independentState = ctx.runtimeState.build.independent;
|
|
29118
|
+
independentState.pendingOutputs = [];
|
|
28641
29119
|
scanService.loadSubPackages();
|
|
28642
29120
|
const dirtyIndependentRoots = scanService.drainIndependentDirtyRoots();
|
|
28643
|
-
const pendingIndependentBuilds = [];
|
|
28644
29121
|
const previousSubPackageRoot = configService.currentSubPackageRoot;
|
|
28645
29122
|
for (const root of dirtyIndependentRoots) {
|
|
28646
29123
|
const meta = scanService.independentSubPackageMap.get(root);
|
|
28647
29124
|
if (!meta) continue;
|
|
28648
|
-
const buildTask = buildService.buildIndependentBundle(root, meta)
|
|
28649
|
-
return {
|
|
28650
|
-
meta,
|
|
28651
|
-
rollup
|
|
28652
|
-
};
|
|
28653
|
-
});
|
|
29125
|
+
const buildTask = buildService.buildIndependentBundle(root, meta);
|
|
28654
29126
|
buildTask.catch(() => {});
|
|
28655
|
-
|
|
29127
|
+
independentState.pendingOutputs.push(buildTask);
|
|
28656
29128
|
try {
|
|
28657
29129
|
await buildTask;
|
|
28658
29130
|
} catch {}
|
|
@@ -28661,7 +29133,6 @@ function createOptionsHook(state) {
|
|
|
28661
29133
|
...configService.options,
|
|
28662
29134
|
currentSubPackageRoot: previousSubPackageRoot
|
|
28663
29135
|
};
|
|
28664
|
-
state.pendingIndependentBuilds = pendingIndependentBuilds;
|
|
28665
29136
|
scannedInput = await collectMainLogicalInputs(state, appEntry);
|
|
28666
29137
|
}
|
|
28667
29138
|
}
|
|
@@ -29812,7 +30283,6 @@ function weappVite(ctx, subPackageMeta) {
|
|
|
29812
30283
|
jsonEmitFilesMap,
|
|
29813
30284
|
resolvedEntryMap,
|
|
29814
30285
|
requireAsyncEmittedChunks: /* @__PURE__ */ new Set(),
|
|
29815
|
-
pendingIndependentBuilds: [],
|
|
29816
30286
|
watchFilesSnapshot: [],
|
|
29817
30287
|
buildTarget,
|
|
29818
30288
|
hmrState,
|
|
@@ -30602,6 +31072,20 @@ function shouldDelegateComponentRegistration(ctx, vuePath, isPage, isApp, config
|
|
|
30602
31072
|
function isVueTransformSourceMapEnabled(configService) {
|
|
30603
31073
|
return Boolean(configService.inlineConfig?.build?.sourcemap);
|
|
30604
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
|
+
}
|
|
30605
31089
|
function resolveVueTemplatePlatformOptions(options) {
|
|
30606
31090
|
const supportsWxs = options.wxsEnabled && typeof options.wxsExtension === "string" && options.wxsExtension.length > 0;
|
|
30607
31091
|
const resolvedWxsExtension = supportsWxs ? options.wxsExtension : void 0;
|
|
@@ -30654,6 +31138,8 @@ function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, conf
|
|
|
30654
31138
|
const objectLiteralBindMode = configService.weappViteConfig?.vue?.template?.objectLiteralBindMode ?? "runtime";
|
|
30655
31139
|
const mustacheInterpolation = configService.weappViteConfig?.vue?.template?.mustacheInterpolation ?? "compact";
|
|
30656
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;
|
|
30657
31143
|
const formatWxmlConfig = configService.weappViteConfig?.vue?.template?.formatWxml ?? "auto";
|
|
30658
31144
|
const formatWxml = formatWxmlConfig === "auto" ? configService.isDev : formatWxmlConfig;
|
|
30659
31145
|
const wxsEnabled = configService.weappViteConfig?.wxs !== false;
|
|
@@ -30777,10 +31263,12 @@ function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, conf
|
|
|
30777
31263
|
objectLiteralBindMode,
|
|
30778
31264
|
mustacheInterpolation,
|
|
30779
31265
|
functionPropNames,
|
|
31266
|
+
templateSafeCallNames,
|
|
30780
31267
|
formatWxml,
|
|
30781
31268
|
wxsExtension: templatePlatformOptions.wxsExtension,
|
|
30782
31269
|
classStyleWxsSrc
|
|
30783
31270
|
},
|
|
31271
|
+
style: { preprocessOptions: resolveSfcStylePreprocessOptions(configService) },
|
|
30784
31272
|
json: {
|
|
30785
31273
|
kind: jsonKind,
|
|
30786
31274
|
defaults: jsonConfig?.defaults,
|
|
@@ -31163,9 +31651,17 @@ async function loadTransformStyleBlock(options) {
|
|
|
31163
31651
|
if (!block) return null;
|
|
31164
31652
|
const dependencies = syncVueSfcStyleDependencies(ctx, filename, styles);
|
|
31165
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);
|
|
31166
31662
|
return {
|
|
31167
|
-
code:
|
|
31168
|
-
map: null
|
|
31663
|
+
code: compiled.code,
|
|
31664
|
+
map: compiled.map ? JSON.parse(compiled.map) : null
|
|
31169
31665
|
};
|
|
31170
31666
|
}
|
|
31171
31667
|
//#endregion
|
|
@@ -31319,18 +31815,20 @@ function logTransformFileError(filename, error) {
|
|
|
31319
31815
|
function hasCssModules(styleBlocks) {
|
|
31320
31816
|
return styleBlocks?.some((styleBlock) => Boolean(styleBlock.module)) === true;
|
|
31321
31817
|
}
|
|
31322
|
-
function refreshStyleOnlyVueTransformResult(result, filename, styleBlocks) {
|
|
31818
|
+
async function refreshStyleOnlyVueTransformResult(result, filename, styleBlocks, stylePreprocessOptions) {
|
|
31323
31819
|
if (!styleBlocks || hasCssModules(styleBlocks)) return false;
|
|
31324
31820
|
if (!styleBlocks.length) {
|
|
31325
31821
|
result.style = void 0;
|
|
31326
31822
|
return true;
|
|
31327
31823
|
}
|
|
31328
31824
|
const scopedId = generateScopedId(filename);
|
|
31329
|
-
result.style = styleBlocks.map((styleBlock) => compileVueStyleToWxss(styleBlock, {
|
|
31825
|
+
result.style = (await Promise.all(styleBlocks.map(async (styleBlock) => await compileVueStyleToWxss(styleBlock, {
|
|
31330
31826
|
id: scopedId,
|
|
31827
|
+
filename,
|
|
31331
31828
|
scoped: styleBlock.scoped,
|
|
31332
|
-
modules: styleBlock.module
|
|
31333
|
-
|
|
31829
|
+
modules: styleBlock.module,
|
|
31830
|
+
preprocessOptions: stylePreprocessOptions?.[styleBlock.lang || "css"]
|
|
31831
|
+
})))).map((result) => result.code.trim()).filter(Boolean).join("\n\n") || void 0;
|
|
31334
31832
|
return true;
|
|
31335
31833
|
}
|
|
31336
31834
|
//#endregion
|
|
@@ -31480,7 +31978,7 @@ async function refreshCompiledVueEntryCacheInDev(options) {
|
|
|
31480
31978
|
source,
|
|
31481
31979
|
checkMtime: configService.isDev
|
|
31482
31980
|
});
|
|
31483
|
-
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;
|
|
31484
31982
|
else {
|
|
31485
31983
|
cached.source = source;
|
|
31486
31984
|
cached.styleIndependentSignature = currentStyleIndependentSignature;
|
|
@@ -32296,7 +32794,7 @@ async function tryReuseVueCompilation(options) {
|
|
|
32296
32794
|
pluginCtx,
|
|
32297
32795
|
configService
|
|
32298
32796
|
}));
|
|
32299
|
-
if (!refreshStyleOnlyVueTransformResult(cachedResult, filename, refreshedStyleBlocks)) {
|
|
32797
|
+
if (!await refreshStyleOnlyVueTransformResult(cachedResult, filename, refreshedStyleBlocks, resolveSfcStylePreprocessOptions(configService))) {
|
|
32300
32798
|
cachedCompilation.styleIndependentSignature = void 0;
|
|
32301
32799
|
canReturnCachedCompilation = false;
|
|
32302
32800
|
} else {
|
|
@@ -32338,7 +32836,7 @@ async function tryReuseVueCompilation(options) {
|
|
|
32338
32836
|
pluginCtx,
|
|
32339
32837
|
configService
|
|
32340
32838
|
}));
|
|
32341
|
-
if (!refreshStyleOnlyVueTransformResult(cachedResult, filename, styleBlocks)) cachedCompilation.styleIndependentSignature = void 0;
|
|
32839
|
+
if (!await refreshStyleOnlyVueTransformResult(cachedResult, filename, styleBlocks, resolveSfcStylePreprocessOptions(configService))) cachedCompilation.styleIndependentSignature = void 0;
|
|
32342
32840
|
else {
|
|
32343
32841
|
cachedCompilation.source = source;
|
|
32344
32842
|
cachedCompilation.result = cachedResult;
|
|
@@ -32978,8 +33476,8 @@ function vitePluginWeapp(ctx, subPackageMeta) {
|
|
|
32978
33476
|
if (autoRoutesEnabled && !libModeEnabled) groups.push(autoRoutes(ctx));
|
|
32979
33477
|
groups.push(autoImport(ctx));
|
|
32980
33478
|
}
|
|
32981
|
-
groups.push(weappVite(ctx, subPackageMeta), wxs(ctx), css(ctx));
|
|
32982
|
-
groups.push([createOutputFinalizerPlugin(ctx)]);
|
|
33479
|
+
groups.push(i18n(ctx, subPackageMeta), weappVite(ctx, subPackageMeta), wxs(ctx), css(ctx));
|
|
33480
|
+
groups.push([createOutputFinalizerPlugin(ctx, subPackageMeta)]);
|
|
32983
33481
|
const assembled = attachRuntimePlugins(ctx, flatten(groups));
|
|
32984
33482
|
if (subPackageMeta) return assembled;
|
|
32985
33483
|
return applyInspect(ctx, assembled);
|
|
@@ -33081,6 +33579,7 @@ function normalizeInlineConfigAfterDefu(inline, options) {
|
|
|
33081
33579
|
...userRolldownOptions?.output ?? {}
|
|
33082
33580
|
}
|
|
33083
33581
|
};
|
|
33582
|
+
if (ctx.configService) normalizePreserveModulesRolldownOptions(ctx.configService, mergedRolldownOptions);
|
|
33084
33583
|
const defaultTsconfig = resolveDefaultRolldownTsconfig(cwd, configFilePath);
|
|
33085
33584
|
const resolveOptions = mergedRolldownOptions.resolve;
|
|
33086
33585
|
if (defaultTsconfig) {
|
|
@@ -33257,6 +33756,7 @@ function mergeWeb(options, ...configs) {
|
|
|
33257
33756
|
}
|
|
33258
33757
|
});
|
|
33259
33758
|
stripRollupOptions(inline);
|
|
33759
|
+
if (options.configService) normalizePreserveModulesRolldownOptions(options.configService, inline.build?.rolldownOptions ?? (inline.build.rolldownOptions = {}));
|
|
33260
33760
|
inline.root = web.root;
|
|
33261
33761
|
inline.configFile = false;
|
|
33262
33762
|
const runtimeProvider = resolveRuntimeProvider("web", "web");
|
|
@@ -33314,6 +33814,7 @@ function mergeWorkers(options, ...configs) {
|
|
|
33314
33814
|
});
|
|
33315
33815
|
applyWeappViteHostMeta(inline, "miniprogram", platform);
|
|
33316
33816
|
stripRollupOptions(inline);
|
|
33817
|
+
normalizePreserveModulesRolldownOptions(ctx.configService, inline.build?.rolldownOptions ?? (inline.build.rolldownOptions = {}));
|
|
33317
33818
|
injectBuiltinAliases(inline);
|
|
33318
33819
|
return inline;
|
|
33319
33820
|
}
|
|
@@ -33327,6 +33828,7 @@ function mergeWorkers(options, ...configs) {
|
|
|
33327
33828
|
applyWeappViteHostMeta(inlineConfig, "miniprogram", platform);
|
|
33328
33829
|
stripRollupOptions(inlineConfig);
|
|
33329
33830
|
inlineConfig.logLevel = "info";
|
|
33831
|
+
normalizePreserveModulesRolldownOptions(ctx.configService, inlineConfig.build?.rolldownOptions ?? (inlineConfig.build.rolldownOptions = {}));
|
|
33330
33832
|
injectBuiltinAliases(inlineConfig);
|
|
33331
33833
|
return inlineConfig;
|
|
33332
33834
|
}
|
|
@@ -33385,6 +33887,7 @@ function createMergeFactories(options) {
|
|
|
33385
33887
|
const subPackageRoots = Object.keys(configService.weappViteConfig?.subPackages ?? {});
|
|
33386
33888
|
const sharedOutput = configService.options.chunksConfigured ? createSharedBuildOutput(configService, () => subPackageRoots, { runtime: "web" }) : void 0;
|
|
33387
33889
|
return backend.driver.mergeConfig({ merge: (...backendConfigs) => mergeWeb({
|
|
33890
|
+
configService,
|
|
33388
33891
|
config: currentOptions.config,
|
|
33389
33892
|
web: currentOptions.weappWeb,
|
|
33390
33893
|
mode: currentOptions.mode,
|
|
@@ -33997,7 +34500,7 @@ async function loadAppEntry(ctx, scanState) {
|
|
|
33997
34500
|
const { path: appEntryPath } = appEntry;
|
|
33998
34501
|
let configFromVue;
|
|
33999
34502
|
if (!appConfigFile && vueAppPath) {
|
|
34000
|
-
const { extractConfigFromVue } = await import("./file-
|
|
34503
|
+
const { extractConfigFromVue } = await import("./file-DPQbjCzZ.mjs");
|
|
34001
34504
|
configFromVue = await extractConfigFromVue(vueAppPath);
|
|
34002
34505
|
if (configFromVue) appConfigFile = vueAppPath;
|
|
34003
34506
|
}
|
|
@@ -34099,6 +34602,7 @@ function coerceStyleConfig(entry) {
|
|
|
34099
34602
|
return {
|
|
34100
34603
|
source,
|
|
34101
34604
|
scope: "all",
|
|
34605
|
+
inject: true,
|
|
34102
34606
|
explicitScope: false
|
|
34103
34607
|
};
|
|
34104
34608
|
}
|
|
@@ -34111,6 +34615,7 @@ function coerceStyleConfig(entry) {
|
|
|
34111
34615
|
scope: hasExplicitScope ? coerceScope(entry.scope) : "all",
|
|
34112
34616
|
include: entry.include,
|
|
34113
34617
|
exclude: entry.exclude,
|
|
34618
|
+
inject: entry.inject !== false,
|
|
34114
34619
|
explicitScope: hasExplicitScope
|
|
34115
34620
|
};
|
|
34116
34621
|
}
|
|
@@ -34157,11 +34662,12 @@ function resolveExcludePatterns(descriptor, normalizedRoot) {
|
|
|
34157
34662
|
}
|
|
34158
34663
|
//#endregion
|
|
34159
34664
|
//#region src/runtime/scanPlugin/styleEntries/entries.ts
|
|
34160
|
-
function createStyleEntryDedupeKey(posixOutput, include, exclude) {
|
|
34665
|
+
function createStyleEntryDedupeKey(posixOutput, include, exclude, inject) {
|
|
34161
34666
|
return JSON.stringify({
|
|
34162
34667
|
file: posixOutput,
|
|
34163
34668
|
include,
|
|
34164
|
-
exclude
|
|
34669
|
+
exclude,
|
|
34670
|
+
inject
|
|
34165
34671
|
});
|
|
34166
34672
|
}
|
|
34167
34673
|
function resolveDefaultScopedStyleEntryCandidates(absoluteSrcRoot, root) {
|
|
@@ -34173,7 +34679,7 @@ function resolveDefaultScopedStyleEntryCandidates(absoluteSrcRoot, root) {
|
|
|
34173
34679
|
absolutePath: path.resolve(absoluteSubRoot, `${base}${ext}`)
|
|
34174
34680
|
})));
|
|
34175
34681
|
}
|
|
34176
|
-
function addStyleEntry(descriptor, absolutePath, posixOutput,
|
|
34682
|
+
function addStyleEntry(descriptor, absolutePath, posixOutput, normalizedRoot, warningPrefix, dedupe, normalized) {
|
|
34177
34683
|
const include = resolveIncludePatterns({
|
|
34178
34684
|
scope: descriptor.scope,
|
|
34179
34685
|
include: descriptor.include
|
|
@@ -34182,10 +34688,10 @@ function addStyleEntry(descriptor, absolutePath, posixOutput, root, normalizedRo
|
|
|
34182
34688
|
include.sort();
|
|
34183
34689
|
exclude.sort();
|
|
34184
34690
|
if (!include.length) {
|
|
34185
|
-
logger_default.warn(
|
|
34691
|
+
logger_default.warn(`${warningPrefix}样式入口 \`${descriptor.source}\` 缺少有效作用范围,已按 \`**/*\` 处理。`);
|
|
34186
34692
|
include.push("**/*");
|
|
34187
34693
|
}
|
|
34188
|
-
const key = createStyleEntryDedupeKey(posixOutput, include, exclude);
|
|
34694
|
+
const key = createStyleEntryDedupeKey(posixOutput, include, exclude, descriptor.inject);
|
|
34189
34695
|
if (dedupe.has(key)) return;
|
|
34190
34696
|
dedupe.add(key);
|
|
34191
34697
|
normalized.push({
|
|
@@ -34195,7 +34701,8 @@ function addStyleEntry(descriptor, absolutePath, posixOutput, root, normalizedRo
|
|
|
34195
34701
|
inputExtension: path.extname(absolutePath).toLowerCase(),
|
|
34196
34702
|
scope: descriptor.scope,
|
|
34197
34703
|
include,
|
|
34198
|
-
exclude
|
|
34704
|
+
exclude,
|
|
34705
|
+
inject: descriptor.inject
|
|
34199
34706
|
});
|
|
34200
34707
|
}
|
|
34201
34708
|
function appendDefaultScopedStyleEntries(root, normalizedRoot, service, dedupe, normalized) {
|
|
@@ -34212,13 +34719,14 @@ function appendDefaultScopedStyleEntries(root, normalizedRoot, service, dedupe,
|
|
|
34212
34719
|
scope: candidate.scope,
|
|
34213
34720
|
include: void 0,
|
|
34214
34721
|
exclude: void 0,
|
|
34722
|
+
inject: true,
|
|
34215
34723
|
explicitScope: true
|
|
34216
34724
|
};
|
|
34217
34725
|
const outputAbsolutePath = changeFileExtension(candidate.absolutePath, service.outputExtensions.wxss);
|
|
34218
34726
|
const outputRelativePath = service.relativeOutputPath(outputAbsolutePath);
|
|
34219
34727
|
if (!outputRelativePath) continue;
|
|
34220
34728
|
const posixOutput = toPosixPath(outputRelativePath);
|
|
34221
|
-
addStyleEntry(descriptor, candidate.absolutePath, posixOutput,
|
|
34729
|
+
addStyleEntry(descriptor, candidate.absolutePath, posixOutput, normalizedRoot, `[分包] 分包 ${root} `, dedupe, normalized);
|
|
34222
34730
|
matchedCurrentBase = true;
|
|
34223
34731
|
}
|
|
34224
34732
|
}
|
|
@@ -34264,6 +34772,13 @@ function inferScopeFromRelativePath(relativePath) {
|
|
|
34264
34772
|
}
|
|
34265
34773
|
//#endregion
|
|
34266
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
|
+
}
|
|
34267
34782
|
function isSupportedSharedStyleExtension(absolutePath) {
|
|
34268
34783
|
return SUPPORTED_SHARED_STYLE_EXTS.has(path.extname(absolutePath).toLowerCase());
|
|
34269
34784
|
}
|
|
@@ -34271,11 +34786,9 @@ function resolveStyleEntryScope(descriptor, posixOutput, normalizedRoot) {
|
|
|
34271
34786
|
if (descriptor.explicitScope) return descriptor.scope;
|
|
34272
34787
|
return inferScopeFromRelativePath(getRelativePathWithinSubPackage(posixOutput, normalizedRoot)) ?? descriptor.scope;
|
|
34273
34788
|
}
|
|
34274
|
-
function
|
|
34789
|
+
function normalizeStyleEntries(styles, root, configService, options) {
|
|
34275
34790
|
const service = configService;
|
|
34276
34791
|
if (!service) return;
|
|
34277
|
-
const root = subPackage.root?.trim();
|
|
34278
|
-
if (!root) return;
|
|
34279
34792
|
const list = styles === void 0 ? [] : Array.isArray(styles) ? styles : [styles];
|
|
34280
34793
|
const normalizedRoot = normalizeRoot(root);
|
|
34281
34794
|
const normalized = [];
|
|
@@ -34283,37 +34796,55 @@ function normalizeSubPackageStyleEntries(styles, subPackage, configService) {
|
|
|
34283
34796
|
for (const entry of list) {
|
|
34284
34797
|
const descriptor = coerceStyleConfig(entry);
|
|
34285
34798
|
if (!descriptor) {
|
|
34286
|
-
logger_default.warn(
|
|
34799
|
+
logger_default.warn(`${options.warningPrefix}样式入口配置无效,已忽略。`);
|
|
34287
34800
|
continue;
|
|
34288
34801
|
}
|
|
34289
34802
|
const absolutePath = resolveStyleEntryAbsolutePath(descriptor.source, root, service);
|
|
34290
34803
|
if (!absolutePath) {
|
|
34291
|
-
logger_default.warn(
|
|
34804
|
+
logger_default.warn(`${options.warningPrefix}样式入口 \`${descriptor.source}\` 解析失败,已忽略。`);
|
|
34292
34805
|
continue;
|
|
34293
34806
|
}
|
|
34294
34807
|
if (!fs.existsSync(absolutePath)) {
|
|
34295
|
-
logger_default.warn(
|
|
34808
|
+
logger_default.warn(`${options.warningPrefix}样式入口 \`${descriptor.source}\` 对应文件不存在,已忽略。`);
|
|
34296
34809
|
continue;
|
|
34297
34810
|
}
|
|
34298
34811
|
if (!isSupportedSharedStyleExtension(absolutePath)) {
|
|
34299
|
-
logger_default.warn(
|
|
34812
|
+
logger_default.warn(`${options.warningPrefix}样式入口 \`${descriptor.source}\` 当前仅支持以下格式:${SUPPORTED_SHARED_STYLE_EXTENSIONS.join(", ")},已忽略。`);
|
|
34300
34813
|
continue;
|
|
34301
34814
|
}
|
|
34302
34815
|
const outputAbsolutePath = changeFileExtension(absolutePath, service.outputExtensions.wxss);
|
|
34303
34816
|
const outputRelativePath = service.relativeOutputPath(outputAbsolutePath);
|
|
34304
34817
|
if (!outputRelativePath) {
|
|
34305
|
-
logger_default.warn(
|
|
34818
|
+
logger_default.warn(`${options.warningPrefix}样式入口 \`${descriptor.source}\` 不在项目源码目录内,已忽略。`);
|
|
34306
34819
|
continue;
|
|
34307
34820
|
}
|
|
34308
34821
|
const posixOutput = toPosixPath(outputRelativePath);
|
|
34309
34822
|
addStyleEntry({
|
|
34310
34823
|
...descriptor,
|
|
34824
|
+
exclude: options.excludeRootAppByDefault && !hasExplicitIncludePattern(descriptor.include, normalizedRoot) ? appendExcludePattern(descriptor.exclude, "app.*") : descriptor.exclude,
|
|
34311
34825
|
scope: resolveStyleEntryScope(descriptor, posixOutput, normalizedRoot)
|
|
34312
|
-
}, absolutePath, posixOutput,
|
|
34826
|
+
}, absolutePath, posixOutput, normalizedRoot, options.warningPrefix, dedupe, normalized);
|
|
34313
34827
|
}
|
|
34314
|
-
appendDefaultScopedStyleEntries(root, normalizedRoot, service, dedupe, normalized);
|
|
34828
|
+
if (options.appendDefaultEntries) appendDefaultScopedStyleEntries(root, normalizedRoot, service, dedupe, normalized);
|
|
34315
34829
|
return normalized.length ? normalized : void 0;
|
|
34316
34830
|
}
|
|
34831
|
+
function normalizeSubPackageStyleEntries(styles, subPackage, configService) {
|
|
34832
|
+
const root = subPackage.root?.trim();
|
|
34833
|
+
if (!root) return;
|
|
34834
|
+
return normalizeStyleEntries(styles, root, configService, {
|
|
34835
|
+
warningPrefix: `[分包] 分包 ${root} `,
|
|
34836
|
+
appendDefaultEntries: true,
|
|
34837
|
+
excludeRootAppByDefault: false
|
|
34838
|
+
});
|
|
34839
|
+
}
|
|
34840
|
+
function normalizeMainPackageStyleEntries(styles, configService) {
|
|
34841
|
+
if (styles === void 0) return;
|
|
34842
|
+
return normalizeStyleEntries(styles, "", configService, {
|
|
34843
|
+
warningPrefix: "[样式] 主包 ",
|
|
34844
|
+
appendDefaultEntries: false,
|
|
34845
|
+
excludeRootAppByDefault: true
|
|
34846
|
+
});
|
|
34847
|
+
}
|
|
34317
34848
|
//#endregion
|
|
34318
34849
|
//#region src/runtime/scanPlugin/subpackages.ts
|
|
34319
34850
|
function resolveSubPackageEntries(subPackage) {
|
|
@@ -34334,6 +34865,7 @@ function loadSubPackages(ctx) {
|
|
|
34334
34865
|
if (scanState.isDirty || subPackageMap.size === 0) {
|
|
34335
34866
|
subPackageMap.clear();
|
|
34336
34867
|
independentSubPackageMap.clear();
|
|
34868
|
+
scanState.mainPackageStyleEntries = normalizeMainPackageStyleEntries(configService.weappViteConfig?.styles, configService);
|
|
34337
34869
|
if (scanState.isDirty) independentDirtyRoots.clear();
|
|
34338
34870
|
if (json) {
|
|
34339
34871
|
const independentSubPackages = [...json.subPackages ?? [], ...json.subpackages ?? []];
|
|
@@ -34341,9 +34873,11 @@ function loadSubPackages(ctx) {
|
|
|
34341
34873
|
const normalizedRoot = subPackage.root ? normalizeRoot(subPackage.root) : void 0;
|
|
34342
34874
|
const subPackageConfig = normalizedRoot ? configService.weappViteConfig?.subPackages?.[normalizedRoot] : void 0;
|
|
34343
34875
|
const npmSubPackageConfig = normalizedRoot ? configService.weappViteConfig?.npm?.subPackages?.[normalizedRoot] : void 0;
|
|
34876
|
+
const independent = subPackage.independent ?? subPackageConfig?.independent;
|
|
34344
34877
|
const resolvedSubPackage = {
|
|
34345
34878
|
...subPackage,
|
|
34346
34879
|
...normalizedRoot ? { root: normalizedRoot } : {},
|
|
34880
|
+
...independent === void 0 ? {} : { independent },
|
|
34347
34881
|
dependencies: npmSubPackageConfig?.dependencies,
|
|
34348
34882
|
inlineConfig: subPackageConfig?.inlineConfig
|
|
34349
34883
|
};
|
|
@@ -34356,7 +34890,7 @@ function loadSubPackages(ctx) {
|
|
|
34356
34890
|
meta.watchSharedStyles = subPackageConfig?.watchSharedStyles ?? true;
|
|
34357
34891
|
if (normalizedRoot) {
|
|
34358
34892
|
subPackageMap.set(normalizedRoot, meta);
|
|
34359
|
-
if (
|
|
34893
|
+
if (resolvedSubPackage.independent) {
|
|
34360
34894
|
independentSubPackageMap.set(normalizedRoot, meta);
|
|
34361
34895
|
if (scanState.isDirty) independentDirtyRoots.add(normalizedRoot);
|
|
34362
34896
|
}
|
|
@@ -34392,6 +34926,9 @@ function createScanService(ctx) {
|
|
|
34392
34926
|
set pluginJsonPath(value) {
|
|
34393
34927
|
scanState.pluginJsonPath = value;
|
|
34394
34928
|
},
|
|
34929
|
+
get mainPackageStyleEntries() {
|
|
34930
|
+
return scanState.mainPackageStyleEntries;
|
|
34931
|
+
},
|
|
34395
34932
|
subPackageMap,
|
|
34396
34933
|
independentSubPackageMap,
|
|
34397
34934
|
async loadAppEntry() {
|
|
@@ -34413,6 +34950,7 @@ function createScanService(ctx) {
|
|
|
34413
34950
|
markDirty() {
|
|
34414
34951
|
scanState.isDirty = true;
|
|
34415
34952
|
scanState.appEntry = void 0;
|
|
34953
|
+
scanState.mainPackageStyleEntries = void 0;
|
|
34416
34954
|
scanState.pluginJson = void 0;
|
|
34417
34955
|
scanState.pluginJsonPath = void 0;
|
|
34418
34956
|
},
|
|
@@ -34978,4 +35516,4 @@ async function createCompilerContext(options) {
|
|
|
34978
35516
|
return ctx;
|
|
34979
35517
|
}
|
|
34980
35518
|
//#endregion
|
|
34981
|
-
export {
|
|
35519
|
+
export { shouldPassPlatformArgToIdeOpen as A, findPreloadRuleKey as C, parseCommentJson as D, loadViteConfigFile as E, createCjsConfigLoadError as O, collectPreloadPages as S, suggestPreloadRules as T, resolveHmrProfileJsonPath as _, formatBytes as a, checkRuntime as b, getSupportedWeappViteTargetDescriptors as c, getBackendForCapability as d, resolveBackendExecution as f, SHARED_CHUNK_VIRTUAL_PREFIX as g, createSharedBuildConfig as h, setActiveCompilerContextKey as i, isPathInside as j, getDefaultIdeProjectRoot as k, isWebPlatform as l, syncManagedTsconfigBootstrapFiles as m, getCompilerContext as n, WEB_PLATFORM_ALIASES as o, syncProjectSupportFiles as p, resetCompilerContext as r, getSupportedWeappVitePlatforms as s, createCompilerContext as t, resolveWeappViteTarget as u, getRouteRuntimeGlobalKeys as v, resolvePreloadPackageIdentifier as w, getProjectConfigFileName as x, resolveWeappConfigFile as y };
|