weapp-vite 6.20.4 → 6.20.5
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 +1 -1
- package/dist/auto-import-components/resolvers.mjs +1 -1
- package/dist/auto-routes.mjs +1 -1
- package/dist/cli.mjs +120 -6
- package/dist/{config-C810aRQQ.d.mts → config-B1H1OqnR.d.mts} +10 -1
- package/dist/config.d.mts +1 -1
- package/dist/{createContext-DoH-W4mj.mjs → createContext-Ryo4nfbU.mjs} +615 -146
- package/dist/docs/README.md +1 -1
- package/dist/docs/ai-workflows.md +2 -0
- package/dist/docs/getting-started.md +13 -2
- package/dist/docs/testing.md +13 -0
- package/dist/docs/uni-app-component-libraries.md +4 -4
- package/dist/docs/weapp-config.md +21 -4
- package/dist/file-BjrPjC70.mjs +2 -0
- package/dist/{file-DnVj_L9_.mjs → file-CWbsTVPm.mjs} +1 -1
- package/dist/getInstance-CJAXp9db.mjs +2 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/json.d.mts +1 -1
- package/dist/mcp.d.mts +1 -1
- package/dist/{resolvers-w4g7O94W.mjs → resolvers-icNxkpcy.mjs} +2 -0
- package/dist/resolvers.mjs +1 -1
- package/dist/test.mjs +1 -1
- package/dist/types.d.mts +2 -2
- package/package.json +18 -18
- package/dist/file-BPMjkByK.mjs +0 -2
- package/dist/getInstance-BPs9XIGi.mjs +0 -2
|
@@ -1,6 +1,6 @@
|
|
|
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-CWbsTVPm.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";
|
|
@@ -15,7 +15,7 @@ import { collectOnPageScrollPerformanceWarnings } from "@weapp-vite/ast/operatio
|
|
|
15
15
|
import { collectSetDataPickKeysFromTemplateCode } from "@weapp-vite/ast/operations/setDataPick";
|
|
16
16
|
import { BABEL_TS_MODULE_PARSER_OPTIONS as BABEL_TS_MODULE_PARSER_OPTIONS$1, generate as generate$1, getVisitorKeys, parse as parse$3, parseJsLike, traverse } from "@weapp-vite/ast/babel";
|
|
17
17
|
import { compileScript, parse as parse$1 } from "vue/compiler-sfc";
|
|
18
|
-
import
|
|
18
|
+
import picomatch from "picomatch";
|
|
19
19
|
import { VUE_COMPONENT_TAG_RE, WE_VU_COMPILER_REACTIVITY_MODULE_ID, WE_VU_COMPILER_RUNTIME_MODULE_ID, WE_VU_COMPILER_TEMPLATE_MODULE_ID, WE_VU_RUNTIME_APIS, buildClassStyleComputedCode, collectVueTemplateTags, compileJsxFile, compileVueFile, compileVueStyleToWxss, createJsonMerger, createPageEntryMatcher, createPageEntryMatcher as createPageEntryMatcher$1, generateScopedId, getClassStyleWxsSource, getMiniProgramTemplatePlatform, getSfcCheckMtime, injectWevuPageFeaturesInJsWithResolver, invalidateFileCache, isAutoImportCandidateTag, isBuiltinComponent, isUniAppCompatibilityFile, pathExists, readAndParseSfc, readFile as readFile$1, refreshVueFileJsonConfig, resolveClassStyleWxsLocation, stripJsonMacroCallsFromCode, transformNestedWxssVars, transformUniAppSource, transformVueDeepSelectors } from "wevu/compiler";
|
|
20
20
|
import process from "node:process";
|
|
21
21
|
import { parse as parse$2, stringify } from "comment-json";
|
|
@@ -38,6 +38,7 @@ import { Buffer } from "node:buffer";
|
|
|
38
38
|
import MagicString from "magic-string";
|
|
39
39
|
import remapping from "@jridgewell/remapping";
|
|
40
40
|
import * as t from "@weapp-vite/ast/babelTypes";
|
|
41
|
+
import { dev } from "rolldown/experimental";
|
|
41
42
|
import babelPresetEnv from "@babel/preset-env";
|
|
42
43
|
import babelPresetTypescript from "@babel/preset-typescript";
|
|
43
44
|
import * as babel from "@weapp-vite/ast/babelCore";
|
|
@@ -1234,7 +1235,7 @@ function getNodeText(node) {
|
|
|
1234
1235
|
concise: true
|
|
1235
1236
|
}).code.trim();
|
|
1236
1237
|
}
|
|
1237
|
-
function getPropertyName(name) {
|
|
1238
|
+
function getPropertyName$1(name) {
|
|
1238
1239
|
if (name.type === "Identifier") return name.name;
|
|
1239
1240
|
if (name.type === "StringLiteral") return name.value;
|
|
1240
1241
|
if (name.type === "NumericLiteral") return String(name.value);
|
|
@@ -1291,7 +1292,7 @@ function resolveTypeFromConfigLiteral(configType) {
|
|
|
1291
1292
|
let constructorType;
|
|
1292
1293
|
for (const member of configType.members) {
|
|
1293
1294
|
if (member.type !== "TSPropertySignature") continue;
|
|
1294
|
-
const key = getPropertyName(member.key);
|
|
1295
|
+
const key = getPropertyName$1(member.key);
|
|
1295
1296
|
const type = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1296
1297
|
if (key === "value" && type && !containsImportType(type)) valueType = getNodeText(type);
|
|
1297
1298
|
else if (key === "type") constructorType = mapConstructorType(type);
|
|
@@ -1301,7 +1302,7 @@ function resolveTypeFromConfigLiteral(configType) {
|
|
|
1301
1302
|
function isPropsConfigLiteral(configType) {
|
|
1302
1303
|
for (const member of configType.members) {
|
|
1303
1304
|
if (member.type !== "TSPropertySignature") continue;
|
|
1304
|
-
const key = getPropertyName(member.key);
|
|
1305
|
+
const key = getPropertyName$1(member.key);
|
|
1305
1306
|
if (key === "type" || key === "value") return true;
|
|
1306
1307
|
}
|
|
1307
1308
|
return false;
|
|
@@ -1310,7 +1311,7 @@ function extractFromPropertiesTypeLiteral(node) {
|
|
|
1310
1311
|
const map = /* @__PURE__ */ new Map();
|
|
1311
1312
|
for (const member of node.members) {
|
|
1312
1313
|
if (member.type !== "TSPropertySignature") continue;
|
|
1313
|
-
const propName = getPropertyName(member.key);
|
|
1314
|
+
const propName = getPropertyName$1(member.key);
|
|
1314
1315
|
if (!propName) continue;
|
|
1315
1316
|
const type = resolveTypeFromConfigLiteral(unwrapTypeAnnotation(member.typeAnnotation)) ?? "any";
|
|
1316
1317
|
map.set(propName, type);
|
|
@@ -1321,7 +1322,7 @@ function extractFromPropsInterfaceMembers(node) {
|
|
|
1321
1322
|
const map = /* @__PURE__ */ new Map();
|
|
1322
1323
|
for (const member of node.body.body) {
|
|
1323
1324
|
if (member.type !== "TSPropertySignature") continue;
|
|
1324
|
-
const propName = getPropertyName(member.key);
|
|
1325
|
+
const propName = getPropertyName$1(member.key);
|
|
1325
1326
|
if (!propName) continue;
|
|
1326
1327
|
const typeNode = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1327
1328
|
if (!typeNode || typeNode.type !== "TSTypeLiteral") continue;
|
|
@@ -1345,7 +1346,7 @@ function extractComponentPropsFromDts(code) {
|
|
|
1345
1346
|
}
|
|
1346
1347
|
for (const member of path.node.body.body) {
|
|
1347
1348
|
if (member.type !== "TSPropertySignature") continue;
|
|
1348
|
-
if (getPropertyName(member.key) !== "properties") continue;
|
|
1349
|
+
if (getPropertyName$1(member.key) !== "properties") continue;
|
|
1349
1350
|
const typeNode = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1350
1351
|
if (typeNode?.type === "TSTypeLiteral") {
|
|
1351
1352
|
props = extractFromPropertiesTypeLiteral(typeNode);
|
|
@@ -1366,7 +1367,7 @@ function extractComponentPropsFromDts(code) {
|
|
|
1366
1367
|
}
|
|
1367
1368
|
for (const member of path.node.body.body) {
|
|
1368
1369
|
if (member.type !== "ClassProperty" && member.type !== "ClassAccessorProperty") continue;
|
|
1369
|
-
if (getPropertyName(member.key) !== "properties") continue;
|
|
1370
|
+
if (getPropertyName$1(member.key) !== "properties") continue;
|
|
1370
1371
|
const typeNode = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1371
1372
|
if (typeNode?.type === "TSTypeLiteral") {
|
|
1372
1373
|
props = extractFromPropertiesTypeLiteral(typeNode);
|
|
@@ -1397,7 +1398,7 @@ function extractInlinePropsTypeFromCode(code) {
|
|
|
1397
1398
|
const pushTypeLiteralMembers = (node) => {
|
|
1398
1399
|
for (const member of node.members) {
|
|
1399
1400
|
if (member.type !== "TSPropertySignature") continue;
|
|
1400
|
-
const propName = getPropertyName(member.key);
|
|
1401
|
+
const propName = getPropertyName$1(member.key);
|
|
1401
1402
|
if (!propName) continue;
|
|
1402
1403
|
const typeNode = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1403
1404
|
props.set(propName, typeNode ? getNodeText(typeNode) : "any");
|
|
@@ -1406,7 +1407,7 @@ function extractInlinePropsTypeFromCode(code) {
|
|
|
1406
1407
|
const pushInterfaceMembers = (node) => {
|
|
1407
1408
|
for (const member of node.body.body) {
|
|
1408
1409
|
if (member.type !== "TSPropertySignature") continue;
|
|
1409
|
-
const propName = getPropertyName(member.key);
|
|
1410
|
+
const propName = getPropertyName$1(member.key);
|
|
1410
1411
|
if (!propName) continue;
|
|
1411
1412
|
const typeNode = unwrapTypeAnnotation(member.typeAnnotation);
|
|
1412
1413
|
props.set(propName, typeNode ? getNodeText(typeNode) : "any");
|
|
@@ -5309,6 +5310,216 @@ async function loadViteConfigFile(configEnv, configFile, configRoot, configFileD
|
|
|
5309
5310
|
return withSuppressedWarningCodes(suppressedWarningCodes, () => loadConfigFromFile(configEnv, resolvedConfigFile, configRoot, logLevel, void 0, resolvedConfigLoader));
|
|
5310
5311
|
}
|
|
5311
5312
|
//#endregion
|
|
5313
|
+
//#region src/utils/preloadScan.ts
|
|
5314
|
+
const ROUTER_METHODS = /* @__PURE__ */ new Set([
|
|
5315
|
+
"navigateTo",
|
|
5316
|
+
"redirectTo",
|
|
5317
|
+
"reLaunch",
|
|
5318
|
+
"switchTab",
|
|
5319
|
+
"push",
|
|
5320
|
+
"replace"
|
|
5321
|
+
]);
|
|
5322
|
+
const TEMPLATE_NAVIGATOR_RE = /<navigator(?=\s|>)[^>]*?\surl\s*=\s*(["'])([^"'{}\s]+)\1/gi;
|
|
5323
|
+
function normalizePagePath$1(value) {
|
|
5324
|
+
return path.posix.normalize(value).replace(/^\/+/, "").replace(/^\.\//, "");
|
|
5325
|
+
}
|
|
5326
|
+
function normalizeStaticTarget(target, sourcePage) {
|
|
5327
|
+
const route = toPosixPath(target).split(/[?#]/, 1)[0];
|
|
5328
|
+
return normalizePagePath$1(route.startsWith("/") ? route : route.startsWith("./") || route.startsWith("../") ? path.posix.join(path.posix.dirname(sourcePage), route) : route);
|
|
5329
|
+
}
|
|
5330
|
+
function getStaticString(node) {
|
|
5331
|
+
if (node?.type === "StringLiteral" || node?.type === "Literal" && typeof node.value === "string") return node.value;
|
|
5332
|
+
if (node?.type === "TemplateLiteral" && node.expressions.length === 0) return node.quasis[0]?.value.cooked ?? node.quasis[0]?.value.raw;
|
|
5333
|
+
}
|
|
5334
|
+
function getPropertyName(node) {
|
|
5335
|
+
if (!node) return;
|
|
5336
|
+
if (node.type === "Identifier" && !node.computed) return node.name;
|
|
5337
|
+
return getStaticString(node);
|
|
5338
|
+
}
|
|
5339
|
+
function getRouteFromObject(argument) {
|
|
5340
|
+
if (argument?.type !== "ObjectExpression") return;
|
|
5341
|
+
for (const property of argument.properties ?? []) {
|
|
5342
|
+
if (property.type !== "ObjectProperty" && property.type !== "Property") continue;
|
|
5343
|
+
const name = getPropertyName(property.key);
|
|
5344
|
+
if (name !== "url" && name !== "path") continue;
|
|
5345
|
+
const value = getStaticString(property.value);
|
|
5346
|
+
if (value) return value;
|
|
5347
|
+
}
|
|
5348
|
+
}
|
|
5349
|
+
function collectScriptTargets(source, sourcePage) {
|
|
5350
|
+
const targets = [];
|
|
5351
|
+
try {
|
|
5352
|
+
const ast = parseJsLike(source);
|
|
5353
|
+
traverse(ast, { CallExpression(callPath) {
|
|
5354
|
+
const callee = callPath.node.callee;
|
|
5355
|
+
const method = callee?.type === "Identifier" ? callee.name : callee?.type === "MemberExpression" ? getPropertyName(callee.property) : void 0;
|
|
5356
|
+
if (!ROUTER_METHODS.has(method)) return;
|
|
5357
|
+
const argument = callPath.node.arguments?.[0];
|
|
5358
|
+
const target = getStaticString(argument) ?? getRouteFromObject(argument);
|
|
5359
|
+
if (target) targets.push(normalizeStaticTarget(target, sourcePage));
|
|
5360
|
+
} });
|
|
5361
|
+
} catch {}
|
|
5362
|
+
return [...new Set(targets)];
|
|
5363
|
+
}
|
|
5364
|
+
function collectTemplateTargets(source, sourcePage) {
|
|
5365
|
+
const targets = [];
|
|
5366
|
+
const withoutComments = source.replace(/<!--[\s\S]*?-->/g, "");
|
|
5367
|
+
TEMPLATE_NAVIGATOR_RE.lastIndex = 0;
|
|
5368
|
+
for (const match of withoutComments.matchAll(TEMPLATE_NAVIGATOR_RE)) {
|
|
5369
|
+
const target = match[2];
|
|
5370
|
+
if (target) targets.push(normalizeStaticTarget(target, sourcePage));
|
|
5371
|
+
}
|
|
5372
|
+
return [...new Set(targets)];
|
|
5373
|
+
}
|
|
5374
|
+
function collectStaticRouteTargets(source, kind, sourcePage) {
|
|
5375
|
+
return kind === "template" ? collectTemplateTargets(source, sourcePage) : collectScriptTargets(source, sourcePage);
|
|
5376
|
+
}
|
|
5377
|
+
//#endregion
|
|
5378
|
+
//#region src/utils/preloadRule.ts
|
|
5379
|
+
const PRELOAD_RULE_GLOB_RE = /[*?[\]{}()!+@]/g;
|
|
5380
|
+
function normalizePagePath(value) {
|
|
5381
|
+
return normalizeRoot(value).replace(/^\/+/, "");
|
|
5382
|
+
}
|
|
5383
|
+
function normalizePackageRoot(value) {
|
|
5384
|
+
return normalizeRoot(value).replace(/^\/+|\/+$/g, "");
|
|
5385
|
+
}
|
|
5386
|
+
function normalizeRule(value, pattern) {
|
|
5387
|
+
if (!isObject(value)) throw new TypeError(`routeRules.${pattern}.preload 必须是对象。`);
|
|
5388
|
+
const packages = value.packages;
|
|
5389
|
+
if (!Array.isArray(packages) || packages.length === 0 || packages.some((item) => typeof item !== "string" || !item.trim())) throw new TypeError(`routeRules.${pattern}.preload.packages 必须是非空字符串数组。`);
|
|
5390
|
+
const network = value.network;
|
|
5391
|
+
if (network !== void 0 && network !== "all" && network !== "wifi") throw new TypeError(`routeRules.${pattern}.preload.network 只能是 "all" 或 "wifi"。`);
|
|
5392
|
+
const normalizedPackages = [...new Set(packages.map((item) => normalizePackageRoot(item)).filter(Boolean))];
|
|
5393
|
+
if (normalizedPackages.length === 0) throw new TypeError(`routeRules.${pattern}.preload.packages 必须包含有效的分包 root。`);
|
|
5394
|
+
return {
|
|
5395
|
+
packages: normalizedPackages,
|
|
5396
|
+
...network === void 0 ? {} : { network }
|
|
5397
|
+
};
|
|
5398
|
+
}
|
|
5399
|
+
function getRuleScore(pattern) {
|
|
5400
|
+
const segments = pattern.split("/").filter(Boolean);
|
|
5401
|
+
const wildcards = pattern.match(PRELOAD_RULE_GLOB_RE) ?? [];
|
|
5402
|
+
PRELOAD_RULE_GLOB_RE.lastIndex = 0;
|
|
5403
|
+
return [
|
|
5404
|
+
segments.filter((segment) => {
|
|
5405
|
+
PRELOAD_RULE_GLOB_RE.lastIndex = 0;
|
|
5406
|
+
return !PRELOAD_RULE_GLOB_RE.test(segment);
|
|
5407
|
+
}).length,
|
|
5408
|
+
pattern.replace(PRELOAD_RULE_GLOB_RE, "").length,
|
|
5409
|
+
-wildcards.length,
|
|
5410
|
+
segments.length,
|
|
5411
|
+
pattern.length
|
|
5412
|
+
];
|
|
5413
|
+
}
|
|
5414
|
+
function compareScores(left, right) {
|
|
5415
|
+
for (let index = 0; index < Math.max(left.length, right.length); index += 1) {
|
|
5416
|
+
const leftValue = left[index] ?? 0;
|
|
5417
|
+
const rightValue = right[index] ?? 0;
|
|
5418
|
+
if (leftValue !== rightValue) return leftValue > rightValue ? 1 : -1;
|
|
5419
|
+
}
|
|
5420
|
+
return 0;
|
|
5421
|
+
}
|
|
5422
|
+
function pageCandidates(page) {
|
|
5423
|
+
const normalized = normalizePagePath(page);
|
|
5424
|
+
const withoutPagesPrefix = normalized.startsWith("pages/") ? normalized.slice(6) : normalized;
|
|
5425
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
5426
|
+
for (const route of [normalized, withoutPagesPrefix]) {
|
|
5427
|
+
const withoutIndex = route.replace(/\/index$/, "") || route;
|
|
5428
|
+
for (const value of [route, withoutIndex]) {
|
|
5429
|
+
candidates.add(value);
|
|
5430
|
+
candidates.add(`/${value}`);
|
|
5431
|
+
}
|
|
5432
|
+
}
|
|
5433
|
+
return [...candidates];
|
|
5434
|
+
}
|
|
5435
|
+
function findRouteRuleMatch(page, routeRules) {
|
|
5436
|
+
if (!routeRules) return;
|
|
5437
|
+
const candidates = pageCandidates(page);
|
|
5438
|
+
let matched;
|
|
5439
|
+
for (const [pattern, value] of Object.entries(routeRules)) {
|
|
5440
|
+
if (!value || value.preload === void 0) continue;
|
|
5441
|
+
if (!candidates.some((candidate) => picomatch(pattern)(candidate))) continue;
|
|
5442
|
+
const rule = normalizeRule(value.preload, pattern);
|
|
5443
|
+
const score = getRuleScore(pattern);
|
|
5444
|
+
if (!matched || compareScores(score, matched.score) > 0) matched = {
|
|
5445
|
+
page,
|
|
5446
|
+
rule,
|
|
5447
|
+
pattern,
|
|
5448
|
+
score
|
|
5449
|
+
};
|
|
5450
|
+
}
|
|
5451
|
+
if (!matched) return;
|
|
5452
|
+
const { score: _score, ...result } = matched;
|
|
5453
|
+
return result;
|
|
5454
|
+
}
|
|
5455
|
+
function collectSubPackages(appJson) {
|
|
5456
|
+
return (Array.isArray(appJson.subPackages) ? appJson.subPackages : Array.isArray(appJson.subpackages) ? appJson.subpackages : []).flatMap((item) => {
|
|
5457
|
+
if (!isObject(item) || typeof item.root !== "string") return [];
|
|
5458
|
+
const root = normalizePackageRoot(item.root);
|
|
5459
|
+
return (Array.isArray(item.pages) ? item.pages.filter((page) => typeof page === "string" && page.trim().length > 0) : []).map((page) => ({
|
|
5460
|
+
route: normalizePagePath(path.posix.join(root, page)),
|
|
5461
|
+
packageRoot: root
|
|
5462
|
+
}));
|
|
5463
|
+
});
|
|
5464
|
+
}
|
|
5465
|
+
function collectPreloadPages(appJson) {
|
|
5466
|
+
return [...Array.isArray(appJson.pages) ? appJson.pages.filter((page) => typeof page === "string" && page.trim().length > 0).map((page) => ({ route: normalizePagePath(page) })) : [], ...collectSubPackages(appJson)];
|
|
5467
|
+
}
|
|
5468
|
+
function findPreloadRuleKey(page, preloadRule) {
|
|
5469
|
+
const candidates = pageCandidates(page);
|
|
5470
|
+
return Object.keys(preloadRule).find((candidate) => candidates.includes(normalizePagePath(candidate)));
|
|
5471
|
+
}
|
|
5472
|
+
function cloneRule(rule) {
|
|
5473
|
+
if (!isObject(rule)) return rule;
|
|
5474
|
+
const packages = Array.isArray(rule.packages) ? rule.packages.filter((item) => typeof item === "string") : [];
|
|
5475
|
+
return {
|
|
5476
|
+
...rule,
|
|
5477
|
+
packages: [...packages]
|
|
5478
|
+
};
|
|
5479
|
+
}
|
|
5480
|
+
/**
|
|
5481
|
+
* @description 将 routeRules 中的 preload 声明合成为 app.json.preloadRule。
|
|
5482
|
+
* 手写的 preloadRule 保持优先,其他平台不生成微信专属字段。
|
|
5483
|
+
*/
|
|
5484
|
+
function applyPreloadRulesToAppJson(appJson, routeRules, platform) {
|
|
5485
|
+
if (platform !== "weapp" || !routeRules) return appJson;
|
|
5486
|
+
const existing = isObject(appJson.preloadRule) ? appJson.preloadRule : {};
|
|
5487
|
+
const next = { ...existing };
|
|
5488
|
+
for (const page of collectPreloadPages(appJson)) {
|
|
5489
|
+
const match = findRouteRuleMatch(page.route, routeRules);
|
|
5490
|
+
if (!match || findPreloadRuleKey(page.route, existing) !== void 0) continue;
|
|
5491
|
+
next[page.route] = cloneRule(match.rule);
|
|
5492
|
+
}
|
|
5493
|
+
if (Object.keys(next).length > 0) appJson.preloadRule = next;
|
|
5494
|
+
return appJson;
|
|
5495
|
+
}
|
|
5496
|
+
function suggestPreloadRules(appJson, pageSources) {
|
|
5497
|
+
const pages = collectPreloadPages(appJson);
|
|
5498
|
+
const packageByRoute = new Map(pages.map((page) => [page.route, page.packageRoot]));
|
|
5499
|
+
const suggestions = [];
|
|
5500
|
+
const uncovered = /* @__PURE__ */ new Set();
|
|
5501
|
+
for (const page of pages) {
|
|
5502
|
+
const source = pageSources.get(page.route);
|
|
5503
|
+
for (const kind of ["template", "script"]) for (const target of collectStaticRouteTargets(source?.[kind] ?? "", kind, page.route)) {
|
|
5504
|
+
const packageRoot = packageByRoute.get(target);
|
|
5505
|
+
if (!packageRoot || packageRoot === page.packageRoot) continue;
|
|
5506
|
+
const suggestion = {
|
|
5507
|
+
page: page.route,
|
|
5508
|
+
packageRoot,
|
|
5509
|
+
target,
|
|
5510
|
+
source: kind
|
|
5511
|
+
};
|
|
5512
|
+
suggestions.push(suggestion);
|
|
5513
|
+
}
|
|
5514
|
+
if (source && !source.template && !source.script) uncovered.add(page.route);
|
|
5515
|
+
}
|
|
5516
|
+
return {
|
|
5517
|
+
pages,
|
|
5518
|
+
suggestions,
|
|
5519
|
+
uncovered: [...uncovered]
|
|
5520
|
+
};
|
|
5521
|
+
}
|
|
5522
|
+
//#endregion
|
|
5312
5523
|
//#region src/utils/projectConfig.ts
|
|
5313
5524
|
async function readProjectConfigFile(filePath, required) {
|
|
5314
5525
|
if (!await fs$1.pathExists(filePath)) {
|
|
@@ -5348,6 +5559,17 @@ async function getProjectConfig(root, options) {
|
|
|
5348
5559
|
async function getProjectPrivateConfig(root, options) {
|
|
5349
5560
|
return await readProjectConfigFile(path.resolve(root, options?.privatePath ?? "project.private.config.json"), false);
|
|
5350
5561
|
}
|
|
5562
|
+
async function disableProjectPrivateConfigHotReload(filePath) {
|
|
5563
|
+
const config = await readProjectConfigFile(filePath, true);
|
|
5564
|
+
const setting = config.setting && typeof config.setting === "object" && !Array.isArray(config.setting) ? config.setting : {};
|
|
5565
|
+
if (setting.compileHotReLoad === false) return false;
|
|
5566
|
+
config.setting = {
|
|
5567
|
+
...setting,
|
|
5568
|
+
compileHotReLoad: false
|
|
5569
|
+
};
|
|
5570
|
+
await fs$1.writeFile(filePath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
5571
|
+
return true;
|
|
5572
|
+
}
|
|
5351
5573
|
function resolveProjectConfigSyncDirs(options) {
|
|
5352
5574
|
const outputRoot = path.dirname(options.outDir);
|
|
5353
5575
|
const sourceBasePath = path.resolve(options.projectConfigPath);
|
|
@@ -5729,7 +5951,7 @@ function createRegistryHelpers(state) {
|
|
|
5729
5951
|
}
|
|
5730
5952
|
const nextKey = globs.join("\0");
|
|
5731
5953
|
if (!state.autoImportState.matcher || state.autoImportState.matcherKey !== nextKey) {
|
|
5732
|
-
state.autoImportState.matcher =
|
|
5954
|
+
state.autoImportState.matcher = picomatch(globs, { windows: true });
|
|
5733
5955
|
state.autoImportState.matcherKey = nextKey;
|
|
5734
5956
|
}
|
|
5735
5957
|
return state.autoImportState.matcher;
|
|
@@ -6212,7 +6434,7 @@ function createRule(pattern) {
|
|
|
6212
6434
|
};
|
|
6213
6435
|
return {
|
|
6214
6436
|
pattern,
|
|
6215
|
-
match:
|
|
6437
|
+
match: picomatch(pattern, { dot: true })
|
|
6216
6438
|
};
|
|
6217
6439
|
}
|
|
6218
6440
|
function isDefaultAutoRouteInclude(include) {
|
|
@@ -6750,14 +6972,12 @@ function normalizeScopedSubPackage(subPackage) {
|
|
|
6750
6972
|
pages: Array.isArray(subPackage.pages) ? subPackage.pages : []
|
|
6751
6973
|
};
|
|
6752
6974
|
}
|
|
6753
|
-
function filterPreloadRule(preloadRule,
|
|
6975
|
+
function filterPreloadRule(preloadRule, scopedPages, scopedPackageIdentifiers, includeMainPackage) {
|
|
6754
6976
|
if (!preloadRule || typeof preloadRule !== "object") return preloadRule;
|
|
6755
|
-
const scopedRoots = new Set(scope.subPackageRoots);
|
|
6756
6977
|
const scopedPreloadRule = {};
|
|
6757
6978
|
for (const [pagePath, rule] of Object.entries(preloadRule)) {
|
|
6758
6979
|
const normalizedPagePath = normalizeRoot(pagePath);
|
|
6759
|
-
|
|
6760
|
-
if (!(pageSubPackageRoot ? scopedRoots.has(pageSubPackageRoot) : scope.includeMainPackage)) continue;
|
|
6980
|
+
if (!scopedPages.has(normalizedPagePath)) continue;
|
|
6761
6981
|
if (!rule || typeof rule !== "object" || !("packages" in rule)) {
|
|
6762
6982
|
scopedPreloadRule[pagePath] = rule;
|
|
6763
6983
|
continue;
|
|
@@ -6768,7 +6988,9 @@ function filterPreloadRule(preloadRule, scope, allSubPackageRoots) {
|
|
|
6768
6988
|
continue;
|
|
6769
6989
|
}
|
|
6770
6990
|
const filteredPackages = packages.filter((packageRoot) => {
|
|
6771
|
-
|
|
6991
|
+
if (typeof packageRoot !== "string") return false;
|
|
6992
|
+
const normalizedPackageRoot = normalizeRoot(packageRoot);
|
|
6993
|
+
return normalizedPackageRoot === "__APP__" ? includeMainPackage : scopedPackageIdentifiers.has(normalizedPackageRoot);
|
|
6772
6994
|
});
|
|
6773
6995
|
if (filteredPackages.length > 0) scopedPreloadRule[pagePath] = {
|
|
6774
6996
|
...rule,
|
|
@@ -6777,18 +6999,49 @@ function filterPreloadRule(preloadRule, scope, allSubPackageRoots) {
|
|
|
6777
6999
|
}
|
|
6778
7000
|
return Object.keys(scopedPreloadRule).length > 0 ? scopedPreloadRule : void 0;
|
|
6779
7001
|
}
|
|
7002
|
+
function collectScopedAppGraph(pages, subPackages) {
|
|
7003
|
+
const mainPages = new Set(pages.map((page) => normalizeRoot(page)));
|
|
7004
|
+
const allPages = new Set(mainPages);
|
|
7005
|
+
const packageIdentifiers = /* @__PURE__ */ new Set();
|
|
7006
|
+
for (const subPackage of subPackages) {
|
|
7007
|
+
const root = normalizeRoot(subPackage.root ?? "");
|
|
7008
|
+
if (!root) continue;
|
|
7009
|
+
packageIdentifiers.add(root);
|
|
7010
|
+
if (typeof subPackage.name === "string" && subPackage.name.trim()) packageIdentifiers.add(normalizeRoot(subPackage.name));
|
|
7011
|
+
for (const page of subPackage.pages ?? []) allPages.add(normalizeRoot(`${root}/${page}`));
|
|
7012
|
+
}
|
|
7013
|
+
return {
|
|
7014
|
+
allPages,
|
|
7015
|
+
mainPages,
|
|
7016
|
+
packageIdentifiers
|
|
7017
|
+
};
|
|
7018
|
+
}
|
|
7019
|
+
function filterTabBar(tabBar, mainPages) {
|
|
7020
|
+
if (!tabBar || !Array.isArray(tabBar.list)) return tabBar;
|
|
7021
|
+
const list = tabBar.list.filter((item) => {
|
|
7022
|
+
return typeof item.pagePath === "string" && mainPages.has(normalizeRoot(item.pagePath));
|
|
7023
|
+
});
|
|
7024
|
+
if (list.length < 2) return;
|
|
7025
|
+
return {
|
|
7026
|
+
...tabBar,
|
|
7027
|
+
list
|
|
7028
|
+
};
|
|
7029
|
+
}
|
|
6780
7030
|
function applyBuildScopeToAppConfig(config, scope) {
|
|
6781
7031
|
if (!scope?.enabled) return config;
|
|
6782
7032
|
const scopedRoots = new Set(scope.subPackageRoots);
|
|
6783
|
-
const
|
|
6784
|
-
const allSubPackageRoots = new Set(sourceSubPackages.map((subPackage) => subPackage.root ? normalizeRoot(subPackage.root) : void 0).filter((root) => Boolean(root)));
|
|
6785
|
-
const scopedSubPackages = sourceSubPackages.filter((subPackage) => isSubPackageInScope(subPackage, scopedRoots)).map(normalizeScopedSubPackage);
|
|
7033
|
+
const scopedSubPackages = (Array.isArray(config.subPackages) ? config.subPackages : Array.isArray(config.subpackages) ? config.subpackages : []).filter((subPackage) => isSubPackageInScope(subPackage, scopedRoots)).map(normalizeScopedSubPackage);
|
|
6786
7034
|
config.pages = scope.includeMainPackage && Array.isArray(config.pages) ? config.pages : [];
|
|
6787
7035
|
config.subPackages = scopedSubPackages;
|
|
6788
7036
|
delete config.subpackages;
|
|
6789
|
-
const
|
|
7037
|
+
const scopedGraph = collectScopedAppGraph(config.pages, scopedSubPackages);
|
|
7038
|
+
const preloadRule = filterPreloadRule(config.preloadRule, scopedGraph.allPages, scopedGraph.packageIdentifiers, scope.includeMainPackage);
|
|
6790
7039
|
if (preloadRule) config.preloadRule = preloadRule;
|
|
6791
7040
|
else delete config.preloadRule;
|
|
7041
|
+
const tabBar = filterTabBar(config.tabBar, scopedGraph.mainPages);
|
|
7042
|
+
if (tabBar) config.tabBar = tabBar;
|
|
7043
|
+
else delete config.tabBar;
|
|
7044
|
+
if (typeof config.entryPagePath === "string" && !scopedGraph.mainPages.has(normalizeRoot(config.entryPagePath))) delete config.entryPagePath;
|
|
6792
7045
|
return config;
|
|
6793
7046
|
}
|
|
6794
7047
|
function applyBuildScopeToAutoRoutes(routes, scope) {
|
|
@@ -7880,18 +8133,65 @@ function resolveCompilerOutputExtensions(outputExtensions) {
|
|
|
7880
8133
|
}
|
|
7881
8134
|
//#endregion
|
|
7882
8135
|
//#region src/runtime/hmrRuntime.ts
|
|
7883
|
-
function
|
|
7884
|
-
|
|
7885
|
-
if (options.platform === "weapp" && options.
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7892
|
-
|
|
7893
|
-
|
|
7894
|
-
|
|
8136
|
+
function resolveHmrRuntimeDecision(options) {
|
|
8137
|
+
const configured = options.configured ?? "auto";
|
|
8138
|
+
if (options.platform === "weapp" && options.skyline === true) return {
|
|
8139
|
+
configured,
|
|
8140
|
+
reason: "skyline-fallback",
|
|
8141
|
+
runtime: "classic"
|
|
8142
|
+
};
|
|
8143
|
+
if (configured === "classic" || configured === "stateful-experimental") return {
|
|
8144
|
+
configured,
|
|
8145
|
+
reason: "explicit",
|
|
8146
|
+
runtime: configured
|
|
8147
|
+
};
|
|
8148
|
+
if (options.platform === "weapp" && options.compileHotReLoad === true) return {
|
|
8149
|
+
configured,
|
|
8150
|
+
reason: "auto-stateful",
|
|
8151
|
+
runtime: "stateful-experimental"
|
|
8152
|
+
};
|
|
8153
|
+
return {
|
|
8154
|
+
configured,
|
|
8155
|
+
reason: options.platform === "weapp" ? "auto-classic" : "auto-non-wechat",
|
|
8156
|
+
runtime: "classic"
|
|
8157
|
+
};
|
|
8158
|
+
}
|
|
8159
|
+
function findSkylineRendererFiles(output) {
|
|
8160
|
+
const jsonConfigs = /* @__PURE__ */ new Map();
|
|
8161
|
+
for (const item of output) {
|
|
8162
|
+
if (item.type !== "asset" || !item.fileName.endsWith(".json")) continue;
|
|
8163
|
+
const source = typeof item.source === "string" ? item.source : item.source instanceof Uint8Array ? new TextDecoder().decode(item.source) : void 0;
|
|
8164
|
+
if (!source) continue;
|
|
8165
|
+
try {
|
|
8166
|
+
const config = JSON.parse(source);
|
|
8167
|
+
if (config && typeof config === "object" && !Array.isArray(config)) jsonConfigs.set(item.fileName.replaceAll("\\", "/"), config);
|
|
8168
|
+
} catch {}
|
|
8169
|
+
}
|
|
8170
|
+
const appConfig = jsonConfigs.get("app.json");
|
|
8171
|
+
if (!appConfig) return [];
|
|
8172
|
+
const configFiles = /* @__PURE__ */ new Set(["app.json"]);
|
|
8173
|
+
if (Array.isArray(appConfig.pages)) {
|
|
8174
|
+
for (const page of appConfig.pages) if (typeof page === "string") configFiles.add(`${page}.json`);
|
|
8175
|
+
}
|
|
8176
|
+
const subPackages = Array.isArray(appConfig.subPackages) ? appConfig.subPackages : Array.isArray(appConfig.subpackages) ? appConfig.subpackages : [];
|
|
8177
|
+
for (const subPackage of subPackages) {
|
|
8178
|
+
if (!subPackage || typeof subPackage !== "object" || Array.isArray(subPackage)) continue;
|
|
8179
|
+
const { pages, root } = subPackage;
|
|
8180
|
+
if (typeof root !== "string" || !Array.isArray(pages)) continue;
|
|
8181
|
+
const normalizedRoot = root.replaceAll("\\", "/").replace(/^\/+|\/+$/g, "");
|
|
8182
|
+
for (const page of pages) if (typeof page === "string") configFiles.add(`${normalizedRoot}/${page}.json`);
|
|
8183
|
+
}
|
|
8184
|
+
return [...configFiles].filter((fileName) => jsonConfigs.get(fileName)?.renderer === "skyline");
|
|
8185
|
+
}
|
|
8186
|
+
function formatHmrRuntimeStartupMessages(decision) {
|
|
8187
|
+
if (decision.reason === "skyline-fallback") return ["HMR 模式:classic(自动降级:Skyline 暂不支持微信开发者工具热重载)", "HMR 切换:切回 WebView 后可手动重新开启微信开发者工具“热重载”。"];
|
|
8188
|
+
if (decision.reason === "runtime-compatibility-fallback") return ["HMR 模式:classic(自动降级:stateful HMR 运行时兼容性检查失败)", "HMR 切换:修复兼容性问题后重启 wv dev,或通过 weapp.hmr.runtime 显式配置 classic。"];
|
|
8189
|
+
if (decision.reason === "explicit") {
|
|
8190
|
+
const alternative = decision.runtime === "classic" ? "stateful-experimental" : "classic";
|
|
8191
|
+
return [`HMR 模式:${decision.runtime}(显式配置)`, `HMR 切换:修改 weapp.hmr.runtime 为 auto 或 ${alternative} 后重启 wv dev。`];
|
|
8192
|
+
}
|
|
8193
|
+
if (decision.reason === "auto-non-wechat") return ["HMR 模式:classic(自动检测:仅微信小程序支持 stateful-experimental)", "HMR 切换:可通过 weapp.hmr.runtime 显式配置 classic。"];
|
|
8194
|
+
if (decision.reason === "auto-stateful") return ["HMR 模式:stateful-experimental(自动检测:微信开发者工具热重载已开启)", "HMR 切换:关闭微信开发者工具“热重载”后重启 wv dev,或通过 weapp.hmr.runtime 显式配置。"];
|
|
7895
8195
|
return ["HMR 模式:classic(自动检测:微信开发者工具热重载未开启或无法确认)", "HMR 切换:开启微信开发者工具“热重载”后重启 wv dev,或通过 weapp.hmr.runtime 显式配置。"];
|
|
7896
8196
|
}
|
|
7897
8197
|
//#endregion
|
|
@@ -10608,7 +10908,7 @@ function resolveNodeModulesSharedPath(cleanedAbsoluteId) {
|
|
|
10608
10908
|
}
|
|
10609
10909
|
function createStringOrRegExpMatcher(pattern) {
|
|
10610
10910
|
if (typeof pattern === "string") {
|
|
10611
|
-
const matcher =
|
|
10911
|
+
const matcher = picomatch(pattern, { dot: true });
|
|
10612
10912
|
return (value) => matcher(value);
|
|
10613
10913
|
}
|
|
10614
10914
|
if (isRegexp(pattern)) return (value) => {
|
|
@@ -11213,6 +11513,8 @@ globalThis[${JSON.stringify(WEAPP_VITE_STATEFUL_HMR_CONTROL_KEY)}] = ${JSON.stri
|
|
|
11213
11513
|
let pendingBatch;
|
|
11214
11514
|
let requestGeneration = 0;
|
|
11215
11515
|
let activeRequest;
|
|
11516
|
+
let lastRequestError;
|
|
11517
|
+
let lastResponse;
|
|
11216
11518
|
let timer;
|
|
11217
11519
|
const sessionId = Date.now().toString(36) + '-' + Math.random().toString(36).slice(2);
|
|
11218
11520
|
const schedule = (delay) => {
|
|
@@ -11236,7 +11538,9 @@ globalThis[${JSON.stringify(WEAPP_VITE_STATEFUL_HMR_CONTROL_KEY)}] = ${JSON.stri
|
|
|
11236
11538
|
success(result) {
|
|
11237
11539
|
if (generation !== requestGeneration) return;
|
|
11238
11540
|
activeRequest = undefined;
|
|
11541
|
+
lastRequestError = undefined;
|
|
11239
11542
|
const type = result?.data?.type;
|
|
11543
|
+
lastResponse = { action, statusCode: result?.statusCode, type };
|
|
11240
11544
|
if (action === 'register' && type === 'registered') {
|
|
11241
11545
|
phase = 'polling';
|
|
11242
11546
|
if (pendingBatch) globalThis[${JSON.stringify(WEAPP_VITE_STATEFUL_HMR_CLIENT_KEY)}].receiveBatch(pendingBatch.meta, pendingBatch.apply);
|
|
@@ -11246,9 +11550,14 @@ globalThis[${JSON.stringify(WEAPP_VITE_STATEFUL_HMR_CONTROL_KEY)}] = ${JSON.stri
|
|
|
11246
11550
|
else if (type === 'rebuilding') schedule(1000);
|
|
11247
11551
|
else schedule(500);
|
|
11248
11552
|
},
|
|
11249
|
-
fail() {
|
|
11553
|
+
fail(error) {
|
|
11250
11554
|
if (generation !== requestGeneration) return;
|
|
11251
11555
|
activeRequest = undefined;
|
|
11556
|
+
lastRequestError = {
|
|
11557
|
+
action,
|
|
11558
|
+
errMsg: String(error?.errMsg || ''),
|
|
11559
|
+
errno: error?.errno,
|
|
11560
|
+
};
|
|
11252
11561
|
schedule(500);
|
|
11253
11562
|
}
|
|
11254
11563
|
});
|
|
@@ -11268,6 +11577,7 @@ globalThis[${JSON.stringify(WEAPP_VITE_STATEFUL_HMR_CONTROL_KEY)}] = ${JSON.stri
|
|
|
11268
11577
|
lastApply: undefined,
|
|
11269
11578
|
getVersion() { return version; },
|
|
11270
11579
|
getLastApply() { return this.lastApply; },
|
|
11580
|
+
getTransportState() { return { phase, version, lastRequestError, lastResponse }; },
|
|
11271
11581
|
stop() {
|
|
11272
11582
|
phase = 'stopped';
|
|
11273
11583
|
if (timer) {
|
|
@@ -11917,6 +12227,36 @@ function createReactPlugin(ctx) {
|
|
|
11917
12227
|
}];
|
|
11918
12228
|
}
|
|
11919
12229
|
//#endregion
|
|
12230
|
+
//#region src/runtime/watch/options.ts
|
|
12231
|
+
/**
|
|
12232
|
+
* 解析主 watcher 与 sidecar watcher 共享的轮询配置。
|
|
12233
|
+
*/
|
|
12234
|
+
function resolvePollingWatchOptions(configService) {
|
|
12235
|
+
const buildWatch = configService.inlineConfig?.build?.watch;
|
|
12236
|
+
const chokidar = buildWatch && typeof buildWatch === "object" && "chokidar" in buildWatch ? buildWatch.chokidar : void 0;
|
|
12237
|
+
const serverWatch = configService.inlineConfig?.server?.watch;
|
|
12238
|
+
const envUsePolling = process.env.CHOKIDAR_USEPOLLING;
|
|
12239
|
+
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
12240
|
+
const envBinaryInterval = process.env.CHOKIDAR_BINARY_INTERVAL;
|
|
12241
|
+
const usePollingCandidate = chokidar?.usePolling ?? serverWatch?.usePolling ?? (envUsePolling === "1" || envUsePolling === "true" ? true : envUsePolling === "0" || envUsePolling === "false" ? false : void 0);
|
|
12242
|
+
const intervalCandidate = chokidar?.interval ?? serverWatch?.interval ?? (envInterval ? Number(envInterval) : void 0);
|
|
12243
|
+
const binaryIntervalCandidate = chokidar?.binaryInterval ?? serverWatch?.binaryInterval ?? (envBinaryInterval ? Number(envBinaryInterval) : void 0);
|
|
12244
|
+
return {
|
|
12245
|
+
usePolling: typeof usePollingCandidate === "boolean" ? usePollingCandidate : void 0,
|
|
12246
|
+
interval: typeof intervalCandidate === "number" && Number.isFinite(intervalCandidate) ? intervalCandidate : void 0,
|
|
12247
|
+
binaryInterval: typeof binaryIntervalCandidate === "number" && Number.isFinite(binaryIntervalCandidate) ? binaryIntervalCandidate : void 0
|
|
12248
|
+
};
|
|
12249
|
+
}
|
|
12250
|
+
function createSidecarWatchOptions(configService, input) {
|
|
12251
|
+
const polling = resolvePollingWatchOptions(configService);
|
|
12252
|
+
return {
|
|
12253
|
+
...input,
|
|
12254
|
+
...polling.usePolling !== void 0 ? { usePolling: polling.usePolling } : {},
|
|
12255
|
+
...typeof polling.interval === "number" ? { interval: polling.interval } : {},
|
|
12256
|
+
...typeof polling.binaryInterval === "number" ? { binaryInterval: polling.binaryInterval } : {}
|
|
12257
|
+
};
|
|
12258
|
+
}
|
|
12259
|
+
//#endregion
|
|
11920
12260
|
//#region src/runtime/statefulHmr/outputWriter.ts
|
|
11921
12261
|
/**
|
|
11922
12262
|
* @description 通过独立的 Vite write 阶段持久化 DevEngine 已生成的文件,不重新解析业务源码。
|
|
@@ -12238,7 +12578,7 @@ var StatefulHmrTransport = class {
|
|
|
12238
12578
|
return {
|
|
12239
12579
|
buildId: this.state.buildId,
|
|
12240
12580
|
token: this.token,
|
|
12241
|
-
url: `http://
|
|
12581
|
+
url: `http://localhost:${port}${endpointPath}`
|
|
12242
12582
|
};
|
|
12243
12583
|
}
|
|
12244
12584
|
handleRequest = async (request, response) => {
|
|
@@ -12380,12 +12720,16 @@ var StatefulHmrViteAdapter = class {
|
|
|
12380
12720
|
config;
|
|
12381
12721
|
server;
|
|
12382
12722
|
callbacks;
|
|
12723
|
+
watchOptions;
|
|
12724
|
+
createDevEngine;
|
|
12383
12725
|
bundledDev;
|
|
12384
12726
|
initialOutputError;
|
|
12385
|
-
constructor(config, server, callbacks) {
|
|
12727
|
+
constructor(config, server, callbacks, watchOptions = {}, createDevEngine = dev) {
|
|
12386
12728
|
this.config = config;
|
|
12387
12729
|
this.server = server;
|
|
12388
12730
|
this.callbacks = callbacks;
|
|
12731
|
+
this.watchOptions = watchOptions;
|
|
12732
|
+
this.createDevEngine = createDevEngine;
|
|
12389
12733
|
}
|
|
12390
12734
|
install() {
|
|
12391
12735
|
const bundledDev = this.server.environments.client.bundledDev;
|
|
@@ -12394,7 +12738,6 @@ var StatefulHmrViteAdapter = class {
|
|
|
12394
12738
|
this.bundledDev = bundledDev;
|
|
12395
12739
|
this.installOptions(bundledDev);
|
|
12396
12740
|
this.installOutput(bundledDev);
|
|
12397
|
-
this.installPatches(bundledDev);
|
|
12398
12741
|
this.installListener(bundledDev);
|
|
12399
12742
|
}
|
|
12400
12743
|
async rebuild(prepare) {
|
|
@@ -12482,34 +12825,46 @@ var StatefulHmrViteAdapter = class {
|
|
|
12482
12825
|
}
|
|
12483
12826
|
};
|
|
12484
12827
|
}
|
|
12485
|
-
installPatches(bundledDev) {
|
|
12486
|
-
const original = bundledDev.handleHmrOutput.bind(bundledDev);
|
|
12487
|
-
bundledDev.handleHmrOutput = (client, files, output, info) => {
|
|
12488
|
-
if (output.type === "Noop") {
|
|
12489
|
-
this.callbacks.onPatch(files, output);
|
|
12490
|
-
return;
|
|
12491
|
-
}
|
|
12492
|
-
if (this.callbacks.onPatch(files, output)) original(client, files, output, info);
|
|
12493
|
-
};
|
|
12494
|
-
}
|
|
12495
12828
|
installListener(bundledDev) {
|
|
12496
|
-
const original = bundledDev.listen.bind(bundledDev);
|
|
12497
12829
|
bundledDev.listen = async () => {
|
|
12498
|
-
await
|
|
12499
|
-
|
|
12500
|
-
const
|
|
12501
|
-
|
|
12502
|
-
|
|
12830
|
+
const rolldownOptions = await bundledDev.getRolldownOptions();
|
|
12831
|
+
if (Array.isArray(rolldownOptions.output) && rolldownOptions.output.length > 1) throw new Error("stateful-experimental HMR 不支持多组 Rolldown output 配置。");
|
|
12832
|
+
const outputOptions = Array.isArray(rolldownOptions.output) ? rolldownOptions.output[0] : rolldownOptions.output;
|
|
12833
|
+
const engine = await this.createDevEngine(rolldownOptions, outputOptions, {
|
|
12834
|
+
onAdditionalAssets: (result) => bundledDev.storeOutputFiles(result.output),
|
|
12835
|
+
onHmrUpdates: (result) => this.handleHmrUpdates(result),
|
|
12836
|
+
onOutput: (result) => {
|
|
12837
|
+
if (result instanceof Error) {
|
|
12838
|
+
this.initialOutputError = result;
|
|
12839
|
+
this.callbacks.onError(result.message);
|
|
12840
|
+
return;
|
|
12841
|
+
}
|
|
12842
|
+
bundledDev.storeOutputFiles(result.output);
|
|
12843
|
+
},
|
|
12844
|
+
watch: {
|
|
12845
|
+
skipWrite: true,
|
|
12846
|
+
...this.watchOptions
|
|
12847
|
+
}
|
|
12848
|
+
});
|
|
12849
|
+
bundledDev._devEngine = engine;
|
|
12850
|
+
engine.run().catch((error) => {
|
|
12851
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
12852
|
+
this.callbacks.onError(message);
|
|
12853
|
+
});
|
|
12854
|
+
await engine.registerClient(clientId);
|
|
12503
12855
|
await engine.ensureCurrentBuildFinish();
|
|
12504
12856
|
if (this.initialOutputError) throw this.initialOutputError;
|
|
12505
12857
|
if ((await engine.getBundleState()).lastBuildErrored) throw new Error("微信状态保持 HMR 初次构建失败。");
|
|
12506
12858
|
await this.callbacks.waitForInitialBundle();
|
|
12507
12859
|
};
|
|
12508
12860
|
}
|
|
12509
|
-
|
|
12510
|
-
if (
|
|
12511
|
-
|
|
12512
|
-
|
|
12861
|
+
handleHmrUpdates(result) {
|
|
12862
|
+
if (result instanceof Error) {
|
|
12863
|
+
this.callbacks.onError(result.message);
|
|
12864
|
+
return;
|
|
12865
|
+
}
|
|
12866
|
+
if (result.changedFiles.length === 0) return;
|
|
12867
|
+
for (const { clientId: updateClientId, update } of result.updates) if (updateClientId === clientId) this.callbacks.onPatch(result.changedFiles, update);
|
|
12513
12868
|
}
|
|
12514
12869
|
};
|
|
12515
12870
|
function createStatefulHmrBanner(chunk) {
|
|
@@ -12546,16 +12901,22 @@ async function runStatefulHmrDev(ctx, buildOptions, restart, snapshots) {
|
|
|
12546
12901
|
const configService = ctx.configService;
|
|
12547
12902
|
if (configService.platform !== "weapp") throw new Error("weapp.hmr.runtime=\"stateful-experimental\" 目前仅支持微信小程序平台。");
|
|
12548
12903
|
let session;
|
|
12904
|
+
const entryIds = new Set(Array.from(snapshots.entryIds, (id) => normalizeFsResolvedId(id)));
|
|
12905
|
+
const pollingWatchOptions = resolvePollingWatchOptions(configService);
|
|
12549
12906
|
const installPlugin = {
|
|
12550
12907
|
name: "weapp-vite:stateful-hmr-session",
|
|
12551
12908
|
enforce: "post",
|
|
12552
12909
|
configureServer(server) {
|
|
12553
|
-
const currentSession = new StatefulHmrSession(ctx, server, restart, snapshots
|
|
12910
|
+
const currentSession = new StatefulHmrSession(ctx, server, restart, entryIds, snapshots, {
|
|
12911
|
+
compareContentsForPolling: pollingWatchOptions.usePolling === true ? true : void 0,
|
|
12912
|
+
pollInterval: pollingWatchOptions.interval,
|
|
12913
|
+
usePolling: pollingWatchOptions.usePolling
|
|
12914
|
+
});
|
|
12554
12915
|
session = currentSession;
|
|
12555
12916
|
currentSession.install();
|
|
12556
12917
|
},
|
|
12557
12918
|
transform(code, id) {
|
|
12558
|
-
if (!isStatefulHmrBoundary(id, configService.absoluteSrcRoot,
|
|
12919
|
+
if (!isStatefulHmrBoundary(id, configService.absoluteSrcRoot, entryIds) || code.includes("import.meta.hot.accept")) return;
|
|
12559
12920
|
return `${id.endsWith(".vue") ? code : redirectNativeComponentRegistration(code)}\nif (import.meta.hot) import.meta.hot.accept();\n`;
|
|
12560
12921
|
}
|
|
12561
12922
|
};
|
|
@@ -12615,6 +12976,7 @@ var StatefulHmrSession = class {
|
|
|
12615
12976
|
ctx;
|
|
12616
12977
|
server;
|
|
12617
12978
|
restart;
|
|
12979
|
+
entryIds;
|
|
12618
12980
|
snapshots;
|
|
12619
12981
|
activeSnapshotBatch;
|
|
12620
12982
|
adapter;
|
|
@@ -12627,10 +12989,11 @@ var StatefulHmrSession = class {
|
|
|
12627
12989
|
sourceChangeListener = (file, dirtyReasonSummary) => {
|
|
12628
12990
|
this.handleSourceUpdate(file, dirtyReasonSummary);
|
|
12629
12991
|
};
|
|
12630
|
-
constructor(ctx, server, restart, snapshots) {
|
|
12992
|
+
constructor(ctx, server, restart, entryIds, snapshots, devWatchOptions) {
|
|
12631
12993
|
this.ctx = ctx;
|
|
12632
12994
|
this.server = server;
|
|
12633
12995
|
this.restart = restart;
|
|
12996
|
+
this.entryIds = entryIds;
|
|
12634
12997
|
this.snapshots = snapshots;
|
|
12635
12998
|
this.replaceSnapshotAssets(snapshots.initial);
|
|
12636
12999
|
this.transport = new StatefulHmrTransport(server, async (buildId, source) => {
|
|
@@ -12648,7 +13011,7 @@ var StatefulHmrSession = class {
|
|
|
12648
13011
|
onOutput: (output) => this.handleOutput(output),
|
|
12649
13012
|
onPatch: (files, output) => this.handlePatch(files, output),
|
|
12650
13013
|
waitForInitialBundle: () => this.waitForInitialBundle()
|
|
12651
|
-
});
|
|
13014
|
+
}, devWatchOptions);
|
|
12652
13015
|
this.snapshotScheduler = new StatefulHmrSnapshotScheduler({
|
|
12653
13016
|
execute: (batch) => this.executeSnapshotBatch(batch),
|
|
12654
13017
|
onError: (error) => this.server.config.logger.error("[weapp-vite] stateful HMR snapshot refresh failed", { error: error instanceof Error ? error : new Error(String(error)) })
|
|
@@ -12716,7 +13079,7 @@ var StatefulHmrSession = class {
|
|
|
12716
13079
|
}
|
|
12717
13080
|
handlePatch(files, output) {
|
|
12718
13081
|
if (output.type === "Noop") return false;
|
|
12719
|
-
if (!isSafeJavaScriptPatch(files, output, this.ctx.runtimeState.build.hmr.profile.dirtyReasonSummary, this.
|
|
13082
|
+
if (!isSafeJavaScriptPatch(files, output, this.ctx.runtimeState.build.hmr.profile.dirtyReasonSummary, this.entryIds, this.server.config.root)) {
|
|
12720
13083
|
if (shouldRestartStatefulHmrServer(files, this.ctx.configService?.configFileDependencies)) this.requestServerRestart();
|
|
12721
13084
|
else if (this.snapshotScheduler.isPending() || files.length > 0 && files.every(isStatefulHmrAssetFile) || shouldUseStatefulHmrSnapshotOnly(this.ctx.runtimeState.build.hmr.profile.dirtyReasonSummary ?? [])) {
|
|
12722
13085
|
if (!this.snapshotScheduler.isPending()) this.requestSnapshotRefresh(files);
|
|
@@ -12908,33 +13271,6 @@ function formatStatefulHmrError(error) {
|
|
|
12908
13271
|
return String(error);
|
|
12909
13272
|
}
|
|
12910
13273
|
//#endregion
|
|
12911
|
-
//#region src/runtime/watch/options.ts
|
|
12912
|
-
function resolvePollingWatchConfig(configService) {
|
|
12913
|
-
const buildWatch = configService.inlineConfig?.build?.watch;
|
|
12914
|
-
const chokidar = buildWatch && typeof buildWatch === "object" && "chokidar" in buildWatch ? buildWatch.chokidar : void 0;
|
|
12915
|
-
const serverWatch = configService.inlineConfig?.server?.watch;
|
|
12916
|
-
const envUsePolling = process.env.CHOKIDAR_USEPOLLING;
|
|
12917
|
-
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
12918
|
-
const envBinaryInterval = process.env.CHOKIDAR_BINARY_INTERVAL;
|
|
12919
|
-
const usePollingCandidate = chokidar?.usePolling ?? serverWatch?.usePolling ?? (envUsePolling === "1" || envUsePolling === "true" ? true : envUsePolling === "0" || envUsePolling === "false" ? false : void 0);
|
|
12920
|
-
const intervalCandidate = chokidar?.interval ?? serverWatch?.interval ?? (envInterval ? Number(envInterval) : void 0);
|
|
12921
|
-
const binaryIntervalCandidate = chokidar?.binaryInterval ?? serverWatch?.binaryInterval ?? (envBinaryInterval ? Number(envBinaryInterval) : void 0);
|
|
12922
|
-
return {
|
|
12923
|
-
usePolling: typeof usePollingCandidate === "boolean" ? usePollingCandidate : void 0,
|
|
12924
|
-
interval: typeof intervalCandidate === "number" && Number.isFinite(intervalCandidate) ? intervalCandidate : void 0,
|
|
12925
|
-
binaryInterval: typeof binaryIntervalCandidate === "number" && Number.isFinite(binaryIntervalCandidate) ? binaryIntervalCandidate : void 0
|
|
12926
|
-
};
|
|
12927
|
-
}
|
|
12928
|
-
function createSidecarWatchOptions(configService, input) {
|
|
12929
|
-
const polling = resolvePollingWatchConfig(configService);
|
|
12930
|
-
return {
|
|
12931
|
-
...input,
|
|
12932
|
-
...polling.usePolling !== void 0 ? { usePolling: polling.usePolling } : {},
|
|
12933
|
-
...typeof polling.interval === "number" ? { interval: polling.interval } : {},
|
|
12934
|
-
...typeof polling.binaryInterval === "number" ? { binaryInterval: polling.binaryInterval } : {}
|
|
12935
|
-
};
|
|
12936
|
-
}
|
|
12937
|
-
//#endregion
|
|
12938
13274
|
//#region src/plugins/autoImport.ts
|
|
12939
13275
|
const LEADING_DOT_SLASH_RE$2 = /^\.\//;
|
|
12940
13276
|
const LEADING_SLASHES_RE$2 = /^\/+/;
|
|
@@ -13682,6 +14018,12 @@ function transformWxsCode(code, options) {
|
|
|
13682
14018
|
const expression = p.node.expression;
|
|
13683
14019
|
if (expression.type === "CallExpression" && expression.callee.type === "MemberExpression" && t.isIdentifier(expression.callee.object) && expression.callee.object.name === "Object" && t.isIdentifier(expression.callee.property) && expression.callee.property.name === "defineProperty" && expression.arguments.length >= 2 && t.isIdentifier(expression.arguments[0]) && expression.arguments[0].name === "exports" && t.isStringLiteral(expression.arguments[1]) && expression.arguments[1].value === "__esModule") p.remove();
|
|
13684
14020
|
},
|
|
14021
|
+
AssignmentExpression: { enter(p) {
|
|
14022
|
+
if (!preserveEsmExports || p.node.operator !== "=") return;
|
|
14023
|
+
const left = p.node.left;
|
|
14024
|
+
if (!t.isMemberExpression(left) || left.computed || !t.isIdentifier(left.object, { name: "module" }) || !t.isIdentifier(left.property, { name: "exports" }) || !p.parentPath.isExpressionStatement()) return;
|
|
14025
|
+
p.parentPath.replaceWith(t.exportDefaultDeclaration(p.node.right));
|
|
14026
|
+
} },
|
|
13685
14027
|
NewExpression: { enter(p) {
|
|
13686
14028
|
const node = p.node;
|
|
13687
14029
|
if (t.isIdentifier(node.callee, { name: "RegExp" })) p.replaceWith(t.callExpression(t.identifier("getRegExp"), node.arguments));
|
|
@@ -15295,8 +15637,50 @@ function createSnapshotSidecarIgnoredMatcher(ctx) {
|
|
|
15295
15637
|
}
|
|
15296
15638
|
function createBuildService(ctx) {
|
|
15297
15639
|
let lastHmrSlowTipProfileCount = 0;
|
|
15298
|
-
let
|
|
15640
|
+
let devHmrDecision;
|
|
15299
15641
|
let devHmrRuntimeNoticeLogged = false;
|
|
15642
|
+
let skylineHmrFallbackApplied = false;
|
|
15643
|
+
const SKYLINE_HMR_COMPATIBILITY_URL = "https://developers.weixin.qq.com/miniprogram/dev/framework/runtime/skyline/migration/compatibility.html#%E5%B8%B8%E8%A7%81%E7%9A%84%E5%85%BC%E5%AE%B9%E9%97%AE%E9%A2%98";
|
|
15644
|
+
function logHmrRuntimeDecision(decision) {
|
|
15645
|
+
if (devHmrRuntimeNoticeLogged) return;
|
|
15646
|
+
devHmrRuntimeNoticeLogged = true;
|
|
15647
|
+
for (const message of formatHmrRuntimeStartupMessages(decision)) logger_default.info(message);
|
|
15648
|
+
}
|
|
15649
|
+
async function applySkylineHmrFallback(options) {
|
|
15650
|
+
const configService = ctx.configService;
|
|
15651
|
+
if (!configService) return false;
|
|
15652
|
+
const currentDecision = devHmrDecision ?? resolveHmrRuntimeDecision({
|
|
15653
|
+
platform: configService.platform,
|
|
15654
|
+
configured: options.configured,
|
|
15655
|
+
compileHotReLoad: options.compileHotReLoad
|
|
15656
|
+
});
|
|
15657
|
+
if (skylineHmrFallbackApplied || currentDecision.runtime === "classic" && options.compileHotReLoad !== true) return false;
|
|
15658
|
+
skylineHmrFallbackApplied = true;
|
|
15659
|
+
devHmrDecision = resolveHmrRuntimeDecision({
|
|
15660
|
+
platform: configService.platform,
|
|
15661
|
+
configured: currentDecision.configured,
|
|
15662
|
+
compileHotReLoad: options.compileHotReLoad,
|
|
15663
|
+
skyline: true
|
|
15664
|
+
});
|
|
15665
|
+
const detectedFiles = options.files.slice(0, 3).join("、");
|
|
15666
|
+
const detectedSuffix = detectedFiles ? `(${detectedFiles})` : "";
|
|
15667
|
+
const privateConfigPath = configService.projectPrivateConfigPath;
|
|
15668
|
+
const privateConfigDisplay = privateConfigPath ? configService.relativeCwd(privateConfigPath) : "project.private.config.json";
|
|
15669
|
+
if (options.compileHotReLoad === true) try {
|
|
15670
|
+
if (!privateConfigPath) throw new Error("无法解析项目私有配置路径");
|
|
15671
|
+
await disableProjectPrivateConfigHotReload(privateConfigPath);
|
|
15672
|
+
const privateConfig = configService.projectPrivateConfig;
|
|
15673
|
+
privateConfig.setting = {
|
|
15674
|
+
...privateConfig.setting && typeof privateConfig.setting === "object" && !Array.isArray(privateConfig.setting) ? privateConfig.setting : {},
|
|
15675
|
+
compileHotReLoad: false
|
|
15676
|
+
};
|
|
15677
|
+
logger_default.warn(`检测到 Skyline 渲染配置${detectedSuffix}。微信开发者工具暂不支持 Skyline 热重载,已将 ${privateConfigDisplay} 中的 setting.compileHotReLoad 设为 false,并降级为 classic。详情:${SKYLINE_HMR_COMPATIBILITY_URL}`);
|
|
15678
|
+
} catch (error) {
|
|
15679
|
+
logger_default.warn(`检测到 Skyline 渲染配置${detectedSuffix}。已降级为 classic,但无法自动关闭 ${privateConfigDisplay} 中的 setting.compileHotReLoad:${error instanceof Error ? error.message : String(error)}。请手动关闭微信开发者工具“热重载”。详情:${SKYLINE_HMR_COMPATIBILITY_URL}`);
|
|
15680
|
+
}
|
|
15681
|
+
else logger_default.warn(`检测到 Skyline 渲染配置${detectedSuffix}。微信开发者工具暂不支持 Skyline 热重载,weapp.hmr.runtime="stateful-experimental" 已自动降级为 classic。详情:${SKYLINE_HMR_COMPATIBILITY_URL}`);
|
|
15682
|
+
return true;
|
|
15683
|
+
}
|
|
15300
15684
|
function createHmrProfileJsonSample(totalMs) {
|
|
15301
15685
|
const profile = ctx.runtimeState.build.hmr.profile;
|
|
15302
15686
|
const relativeFile = profile.file && ctx.configService ? ctx.configService.relativeCwd(profile.file) : void 0;
|
|
@@ -15857,31 +16241,47 @@ function createBuildService(ctx) {
|
|
|
15857
16241
|
if (process.env.NODE_ENV === void 0) process.env.NODE_ENV = "development";
|
|
15858
16242
|
debug$2?.(`[${target}] dev build watcher start`);
|
|
15859
16243
|
const { hasWorkersDir, workersDir } = checkWorkersOptions(target, configService, scanService);
|
|
15860
|
-
const createDevBuildOptions = () => appendHmrMetricsPlugin(applyTargetBuildOverride(configService.merge(void 0, createSharedBuildConfig(configService, scanService), resolveTargetBuildOverride(target)), target));
|
|
15861
|
-
let buildOptions = createDevBuildOptions();
|
|
15862
|
-
buildOptions.build = {
|
|
15863
|
-
...buildOptions.build ?? {},
|
|
15864
|
-
write: true
|
|
15865
|
-
};
|
|
15866
16244
|
const configuredHmrRuntime = configService.weappViteConfig.hmr?.runtime;
|
|
15867
16245
|
const compileHotReLoad = configService.projectPrivateConfig.setting?.compileHotReLoad;
|
|
15868
|
-
|
|
16246
|
+
devHmrDecision ??= resolveHmrRuntimeDecision({
|
|
15869
16247
|
platform: configService.platform,
|
|
15870
16248
|
configured: configuredHmrRuntime,
|
|
15871
16249
|
compileHotReLoad
|
|
15872
16250
|
});
|
|
15873
|
-
const
|
|
15874
|
-
|
|
15875
|
-
|
|
15876
|
-
|
|
15877
|
-
|
|
15878
|
-
|
|
15879
|
-
|
|
15880
|
-
|
|
15881
|
-
|
|
15882
|
-
|
|
15883
|
-
|
|
15884
|
-
|
|
16251
|
+
const createDevBuildOptions = () => {
|
|
16252
|
+
const options = applyTargetBuildOverride(configService.merge(void 0, createSharedBuildConfig(configService, scanService), resolveTargetBuildOverride(target)), target);
|
|
16253
|
+
if (target === "app" && devHmrDecision?.runtime === "classic") {
|
|
16254
|
+
let skylineFiles = [];
|
|
16255
|
+
options.plugins = [...options.plugins ?? [], {
|
|
16256
|
+
name: "weapp-vite:skyline-hmr-compatibility",
|
|
16257
|
+
enforce: "post",
|
|
16258
|
+
generateBundle(_options, bundle) {
|
|
16259
|
+
skylineFiles = findSkylineRendererFiles(Object.values(bundle));
|
|
16260
|
+
},
|
|
16261
|
+
writeBundle() {
|
|
16262
|
+
if (skylineFiles.length === 0) return;
|
|
16263
|
+
const detectedFiles = skylineFiles;
|
|
16264
|
+
skylineFiles = [];
|
|
16265
|
+
setTimeout(() => {
|
|
16266
|
+
applySkylineHmrFallback({
|
|
16267
|
+
compileHotReLoad,
|
|
16268
|
+
configured: devHmrDecision?.configured,
|
|
16269
|
+
files: detectedFiles
|
|
16270
|
+
});
|
|
16271
|
+
}, 0);
|
|
16272
|
+
}
|
|
16273
|
+
}];
|
|
16274
|
+
}
|
|
16275
|
+
return appendHmrMetricsPlugin(options);
|
|
16276
|
+
};
|
|
16277
|
+
let buildOptions = createDevBuildOptions();
|
|
16278
|
+
buildOptions.build = {
|
|
16279
|
+
...buildOptions.build ?? {},
|
|
16280
|
+
write: true
|
|
16281
|
+
};
|
|
16282
|
+
const hmrDecision = devHmrDecision;
|
|
16283
|
+
if (target === "app" && hmrDecision.runtime !== "stateful-experimental") logHmrRuntimeDecision(hmrDecision);
|
|
16284
|
+
if (target === "app" && hmrDecision.runtime === "stateful-experimental") try {
|
|
15885
16285
|
const snapshotBuildOptions = {
|
|
15886
16286
|
...buildOptions,
|
|
15887
16287
|
build: {
|
|
@@ -15891,6 +16291,21 @@ function createBuildService(ctx) {
|
|
|
15891
16291
|
}
|
|
15892
16292
|
};
|
|
15893
16293
|
const initialSnapshot = toStatefulHmrOutput(await build(snapshotBuildOptions));
|
|
16294
|
+
const initialEntryIds = new Set(ctx.runtimeState.build.hmr.resolvedEntryMap.keys());
|
|
16295
|
+
const skylineFiles = findSkylineRendererFiles(initialSnapshot);
|
|
16296
|
+
if (skylineFiles.length > 0) await applySkylineHmrFallback({
|
|
16297
|
+
compileHotReLoad,
|
|
16298
|
+
configured: hmrDecision.configured,
|
|
16299
|
+
files: skylineFiles
|
|
16300
|
+
});
|
|
16301
|
+
if (devHmrDecision?.runtime === "classic") {
|
|
16302
|
+
resetRuntimeStateForFreshBuild(ctx.runtimeState);
|
|
16303
|
+
await configService.load(configService.loadOptions);
|
|
16304
|
+
await scanService.loadAppEntry();
|
|
16305
|
+
scanService.loadSubPackages();
|
|
16306
|
+
return await runDev(target);
|
|
16307
|
+
}
|
|
16308
|
+
logHmrRuntimeDecision(hmrDecision);
|
|
15894
16309
|
await configService.load(configService.loadOptions);
|
|
15895
16310
|
resetRuntimeStateForFreshBuild(ctx.runtimeState);
|
|
15896
16311
|
await scanService.loadAppEntry();
|
|
@@ -15912,6 +16327,7 @@ function createBuildService(ctx) {
|
|
|
15912
16327
|
await runDev(target);
|
|
15913
16328
|
logger_default.success("微信状态保持 HMR 构建已完成完整重载。");
|
|
15914
16329
|
}, {
|
|
16330
|
+
entryIds: initialEntryIds,
|
|
15915
16331
|
initial: initialSnapshot,
|
|
15916
16332
|
rebuild: async (files) => {
|
|
15917
16333
|
for (const file of files) invalidateFileCache(file);
|
|
@@ -15940,10 +16356,14 @@ function createBuildService(ctx) {
|
|
|
15940
16356
|
watcherService.setRollupWatcher(watcher, "/");
|
|
15941
16357
|
return watcher;
|
|
15942
16358
|
} catch (error) {
|
|
15943
|
-
if (
|
|
15944
|
-
|
|
16359
|
+
if (hmrDecision.configured !== "auto" || !isStatefulHmrRuntimeCompatibilityError(error)) throw error;
|
|
16360
|
+
devHmrDecision = {
|
|
16361
|
+
configured: hmrDecision.configured,
|
|
16362
|
+
reason: "runtime-compatibility-fallback",
|
|
16363
|
+
runtime: "classic"
|
|
16364
|
+
};
|
|
15945
16365
|
logger_default.warn(`微信状态保持 HMR 运行时不可用,已自动降级为 classic:${error instanceof Error ? error.message : String(error)}`);
|
|
15946
|
-
logger_default.info(
|
|
16366
|
+
logger_default.info(formatHmrRuntimeStartupMessages(devHmrDecision)[0]);
|
|
15947
16367
|
resetRuntimeStateForFreshBuild(ctx.runtimeState);
|
|
15948
16368
|
await configService.load(configService.loadOptions);
|
|
15949
16369
|
await scanService.loadAppEntry();
|
|
@@ -18894,6 +19314,7 @@ function emitSfcJsonAsset(ctx, bundle, relativeBase, result, options) {
|
|
|
18894
19314
|
if (!nextConfig) return;
|
|
18895
19315
|
if (options.emitIfMissingOnly) {
|
|
18896
19316
|
if (!bundle[jsonFileName]) {
|
|
19317
|
+
nextConfig = options.finalizeConfig?.(nextConfig) ?? nextConfig;
|
|
18897
19318
|
const nextSource = JSON.stringify(nextConfig, null, 2);
|
|
18898
19319
|
if (emittedAssetSourceCache.get(cacheKey) !== nextSource) {
|
|
18899
19320
|
ctx.emitFile({
|
|
@@ -18908,19 +19329,23 @@ function emitSfcJsonAsset(ctx, bundle, relativeBase, result, options) {
|
|
|
18908
19329
|
}
|
|
18909
19330
|
if (options.mergeExistingAsset && existing && existing.type === "asset") {
|
|
18910
19331
|
try {
|
|
18911
|
-
const
|
|
19332
|
+
const mergedConfig = mergeJson(JSON.parse(existing.source.toString()), nextConfig, "merge-existing");
|
|
19333
|
+
const merged = options.finalizeConfig?.(mergedConfig) ?? mergedConfig;
|
|
18912
19334
|
existing.source = JSON.stringify(merged, null, 2);
|
|
18913
19335
|
} catch {
|
|
19336
|
+
nextConfig = options.finalizeConfig?.(nextConfig) ?? nextConfig;
|
|
18914
19337
|
existing.source = JSON.stringify(nextConfig, null, 2);
|
|
18915
19338
|
}
|
|
18916
19339
|
return;
|
|
18917
19340
|
}
|
|
18918
19341
|
if (existing && existing.type === "asset") {
|
|
19342
|
+
nextConfig = options.finalizeConfig?.(nextConfig) ?? nextConfig;
|
|
18919
19343
|
const nextSource = JSON.stringify(nextConfig, null, 2);
|
|
18920
19344
|
if ((existing.source?.toString?.() ?? "") !== nextSource) existing.source = nextSource;
|
|
18921
19345
|
emittedAssetSourceCache.set(cacheKey, nextSource);
|
|
18922
19346
|
return;
|
|
18923
19347
|
}
|
|
19348
|
+
nextConfig = options.finalizeConfig?.(nextConfig) ?? nextConfig;
|
|
18924
19349
|
const nextSource = JSON.stringify(nextConfig, null, 2);
|
|
18925
19350
|
if (emittedAssetSourceCache.get(cacheKey) === nextSource) return;
|
|
18926
19351
|
ctx.emitFile({
|
|
@@ -19718,7 +20143,7 @@ function stripQueryAndHash(value) {
|
|
|
19718
20143
|
}
|
|
19719
20144
|
function createPathMatcher(patterns, options) {
|
|
19720
20145
|
if (!patterns.length) return () => false;
|
|
19721
|
-
return
|
|
20146
|
+
return picomatch(patterns.map((pattern) => normalizePath$1(pattern)), options);
|
|
19722
20147
|
}
|
|
19723
20148
|
function createAssetPathVariants(file, roots) {
|
|
19724
20149
|
const variants = [file];
|
|
@@ -20457,15 +20882,26 @@ function createExtendedLibManager() {
|
|
|
20457
20882
|
};
|
|
20458
20883
|
}
|
|
20459
20884
|
//#endregion
|
|
20885
|
+
//#region src/runtime/appConfig.ts
|
|
20886
|
+
function finalizeAppConfigForBuild(config, options) {
|
|
20887
|
+
return applyBuildScopeToAppConfig(applyPreloadRulesToAppJson(normalizeAppJson(config), options.routeRules, options.platform), resolveBuildScope(options.buildScope));
|
|
20888
|
+
}
|
|
20889
|
+
//#endregion
|
|
20460
20890
|
//#region src/plugins/hooks/useLoadEntry/jsonEmit.ts
|
|
20461
20891
|
function createJsonEmitManager(configService) {
|
|
20462
20892
|
const map = /* @__PURE__ */ new Map();
|
|
20463
20893
|
function register(entry) {
|
|
20464
20894
|
if (!entry.jsonPath && !entry.fileName) return;
|
|
20465
20895
|
const fileName = entry.fileName ?? resolveRelativeJsonOutputFileName(configService, entry.jsonPath);
|
|
20466
|
-
const
|
|
20896
|
+
const shouldNormalizeAppJson = entry.type === "app" && fileName === "app.json";
|
|
20897
|
+
const weappViteConfig = configService.weappViteConfig ?? {};
|
|
20898
|
+
const normalizedEntry = shouldNormalizeAppJson ? {
|
|
20467
20899
|
...entry,
|
|
20468
|
-
json:
|
|
20900
|
+
json: finalizeAppConfigForBuild(entry.json, {
|
|
20901
|
+
buildScope: weappViteConfig.buildScope,
|
|
20902
|
+
platform: configService.platform,
|
|
20903
|
+
routeRules: weappViteConfig.routeRules
|
|
20904
|
+
})
|
|
20469
20905
|
} : entry;
|
|
20470
20906
|
map.set(fileName, {
|
|
20471
20907
|
fileName,
|
|
@@ -21279,7 +21715,7 @@ function resolveRouteRuleLayoutMeta(filename, configService) {
|
|
|
21279
21715
|
const routeCandidates = normalizePageRouteCandidates(filename, configService);
|
|
21280
21716
|
let matched;
|
|
21281
21717
|
for (const [pattern, rule] of Object.entries(routeRules)) {
|
|
21282
|
-
if (!routeCandidates.some((candidate) =>
|
|
21718
|
+
if (!routeCandidates.some((candidate) => picomatch(pattern)(candidate))) continue;
|
|
21283
21719
|
const normalizedMeta = normalizeRouteRuleLayoutMeta(rule?.appLayout);
|
|
21284
21720
|
const patternSegments = pattern.split("/").filter(Boolean);
|
|
21285
21721
|
const wildcardMatches = pattern.match(ROUTE_RULE_GLOB_TOKEN_RE) ?? [];
|
|
@@ -21534,6 +21970,7 @@ async function collectAppEntries(options) {
|
|
|
21534
21970
|
let pluginJsonPathForRegistration;
|
|
21535
21971
|
let pluginJsonForRegistration;
|
|
21536
21972
|
let pluginSignature;
|
|
21973
|
+
let appJson;
|
|
21537
21974
|
if (!isPluginBuild) {
|
|
21538
21975
|
extendedLibManager.syncFromAppJson(json);
|
|
21539
21976
|
await Promise.all([collectAppSideFiles(pluginCtx, id, json, jsonService, registerJsonAsset, existsCache, pathExistsTtlMs), collectMiniappConfigFile(pluginCtx, id, configService, jsonService, registerJsonAsset, existsCache, pathExistsTtlMs)]);
|
|
@@ -21555,6 +21992,7 @@ async function collectAppEntries(options) {
|
|
|
21555
21992
|
const pluginSignatureMatches = cached.pluginSignature === pluginSignature;
|
|
21556
21993
|
if (cached.appSignature === appSignature && pluginPathMatches && pluginSignatureMatches) return {
|
|
21557
21994
|
entries: cached.entries,
|
|
21995
|
+
appJson: cached.appJson,
|
|
21558
21996
|
pluginResolvedRecords: cached.pluginResolvedRecords,
|
|
21559
21997
|
pluginEntryTypes: cached.pluginEntryTypes,
|
|
21560
21998
|
pluginJsonPathForRegistration: cached.pluginJsonPathForRegistration,
|
|
@@ -21566,11 +22004,10 @@ async function collectAppEntries(options) {
|
|
|
21566
22004
|
};
|
|
21567
22005
|
}
|
|
21568
22006
|
if (!isPluginBuild) {
|
|
21569
|
-
|
|
21570
|
-
|
|
21571
|
-
|
|
21572
|
-
|
|
21573
|
-
type: "app"
|
|
22007
|
+
appJson = finalizeAppConfigForBuild(json, {
|
|
22008
|
+
buildScope: configService.weappViteConfig.buildScope,
|
|
22009
|
+
platform: configService.platform,
|
|
22010
|
+
routeRules: configService.weappViteConfig.routeRules
|
|
21574
22011
|
});
|
|
21575
22012
|
entries.push(...analyzeAppJson(appJson));
|
|
21576
22013
|
}
|
|
@@ -21600,6 +22037,7 @@ async function collectAppEntries(options) {
|
|
|
21600
22037
|
}
|
|
21601
22038
|
if (useCache && cache) cache.current = {
|
|
21602
22039
|
appSignature,
|
|
22040
|
+
appJson,
|
|
21603
22041
|
pluginSignature,
|
|
21604
22042
|
pluginJsonPath,
|
|
21605
22043
|
entries: [...entries],
|
|
@@ -21610,6 +22048,7 @@ async function collectAppEntries(options) {
|
|
|
21610
22048
|
};
|
|
21611
22049
|
return {
|
|
21612
22050
|
entries,
|
|
22051
|
+
appJson,
|
|
21613
22052
|
pluginResolvedRecords,
|
|
21614
22053
|
pluginEntryTypes,
|
|
21615
22054
|
pluginJsonPathForRegistration,
|
|
@@ -22423,7 +22862,7 @@ async function emitEntryOutput(options) {
|
|
|
22423
22862
|
}
|
|
22424
22863
|
}
|
|
22425
22864
|
if (!isPluginBuild || type !== "app") registerJsonAsset({
|
|
22426
|
-
jsonPath,
|
|
22865
|
+
jsonPath: type === "app" ? id : jsonPath,
|
|
22427
22866
|
json,
|
|
22428
22867
|
type
|
|
22429
22868
|
});
|
|
@@ -22774,6 +23213,7 @@ function createEntryLoader(options) {
|
|
|
22774
23213
|
extendedLibManager,
|
|
22775
23214
|
cache: appEntriesCache
|
|
22776
23215
|
});
|
|
23216
|
+
if (appResult.appJson) json = appResult.appJson;
|
|
22777
23217
|
autoRoutesSignature = configService.isDev ? ctx.autoRoutesService?.getSignature?.() : void 0;
|
|
22778
23218
|
entries.push(...appResult.entries);
|
|
22779
23219
|
const registerAppComponentEntry = (entry) => {
|
|
@@ -25333,8 +25773,8 @@ function getStyleMatcher(entry) {
|
|
|
25333
25773
|
if (cached) return cached;
|
|
25334
25774
|
const includePatterns = entry.include?.length ? entry.include : ["**/*"];
|
|
25335
25775
|
const excludePatterns = entry.exclude?.length ? entry.exclude : void 0;
|
|
25336
|
-
const matcher = { include:
|
|
25337
|
-
if (excludePatterns?.length) matcher.exclude =
|
|
25776
|
+
const matcher = { include: picomatch(includePatterns, { dot: true }) };
|
|
25777
|
+
if (excludePatterns?.length) matcher.exclude = picomatch(excludePatterns, { dot: true });
|
|
25338
25778
|
styleMatcherCache.set(entry, matcher);
|
|
25339
25779
|
return matcher;
|
|
25340
25780
|
}
|
|
@@ -28417,16 +28857,16 @@ function resolveEntryRecord(state, sourceId) {
|
|
|
28417
28857
|
const relativeBase = removeExtensionDeep(state.ctx.configService.relativeAbsoluteSrcRoot(sourceId));
|
|
28418
28858
|
return state.entriesMap.get(relativeBase) ?? state.entriesMap.get(removeExtensionDeep(sourceId));
|
|
28419
28859
|
}
|
|
28420
|
-
async function resolveLocalModule(
|
|
28860
|
+
async function resolveLocalModule(pluginContext, source, importer) {
|
|
28421
28861
|
const localBase = path.isAbsolute(source) ? source : source.startsWith("/") ? source : path.resolve(path.dirname(importer), source);
|
|
28422
|
-
const resolved = await
|
|
28862
|
+
const resolved = await pluginContext.resolve(localBase, importer);
|
|
28423
28863
|
if (resolved?.id) return normalizeFsResolvedId(resolved.id);
|
|
28424
28864
|
if (path.isAbsolute(localBase) && !path.extname(localBase)) {
|
|
28425
28865
|
const localEntry = (await findJsEntry(localBase)).path ?? await findVueEntry(localBase);
|
|
28426
|
-
if (localEntry) return normalizeFsResolvedId((await
|
|
28866
|
+
if (localEntry) return normalizeFsResolvedId((await pluginContext.resolve(localEntry, importer))?.id ?? localEntry);
|
|
28427
28867
|
}
|
|
28428
28868
|
}
|
|
28429
|
-
async function collectUsingComponentDependencies(state, ownerId, json) {
|
|
28869
|
+
async function collectUsingComponentDependencies(state, pluginContext, ownerId, json) {
|
|
28430
28870
|
if (!json || typeof json !== "object" || !("usingComponents" in json)) return [];
|
|
28431
28871
|
const usingComponents = json.usingComponents;
|
|
28432
28872
|
if (!usingComponents || typeof usingComponents !== "object" || Array.isArray(usingComponents)) return [];
|
|
@@ -28434,7 +28874,7 @@ async function collectUsingComponentDependencies(state, ownerId, json) {
|
|
|
28434
28874
|
for (const value of Object.values(usingComponents)) {
|
|
28435
28875
|
if (typeof value !== "string" || !value || value.includes("://")) continue;
|
|
28436
28876
|
const outputKey = removeExtensionDeep(value).replace(/^\/+/, "");
|
|
28437
|
-
const resolved = await resolveLocalModule(
|
|
28877
|
+
const resolved = await resolveLocalModule(pluginContext, state.ctx.runtimeState.build.hmr.externalComponentEntryMap.get(outputKey) ?? (value.startsWith("/") ? path.resolve(state.ctx.configService.absoluteSrcRoot, value.slice(1)) : value), ownerId);
|
|
28438
28878
|
if (resolved) dependencies.push({
|
|
28439
28879
|
kind: "using-component",
|
|
28440
28880
|
sourceId: resolved
|
|
@@ -28451,7 +28891,7 @@ function collectTemplateDependencies(state, templatePath) {
|
|
|
28451
28891
|
});
|
|
28452
28892
|
return dependencies;
|
|
28453
28893
|
}
|
|
28454
|
-
async function collectLogicalEntryDependencies(state, ownerId) {
|
|
28894
|
+
async function collectLogicalEntryDependencies(state, pluginContext, ownerId) {
|
|
28455
28895
|
const pendingDependencies = state.ctx.moduleGraphService.getEntryDependencies(ownerId);
|
|
28456
28896
|
const dependencies = [];
|
|
28457
28897
|
const addExistingDependency = async (kind, sourceId) => {
|
|
@@ -28476,7 +28916,7 @@ async function collectLogicalEntryDependencies(state, ownerId) {
|
|
|
28476
28916
|
await addExistingDependency("style", styleEntry.path);
|
|
28477
28917
|
if (templatePath) await state.ctx.wxmlService?.scan(templatePath);
|
|
28478
28918
|
dependencies.push(...collectTemplateDependencies(state, templatePath));
|
|
28479
|
-
dependencies.push(...await collectUsingComponentDependencies(state, ownerId, entry?.json));
|
|
28919
|
+
dependencies.push(...await collectUsingComponentDependencies(state, pluginContext, ownerId, entry?.json));
|
|
28480
28920
|
for (const kind of [
|
|
28481
28921
|
"json",
|
|
28482
28922
|
"jsx",
|
|
@@ -28500,7 +28940,7 @@ function createLogicalEntryResolveHook(state) {
|
|
|
28500
28940
|
if (!sidecarSource) return null;
|
|
28501
28941
|
state.ctx.moduleGraphService.bindPluginContext(this);
|
|
28502
28942
|
return {
|
|
28503
|
-
id: (await
|
|
28943
|
+
id: (await this.resolve(id, importer, { skipSelf: true }))?.id ?? createSidecarSourceSpecifier(sidecarSource.ownerId, sidecarSource.sourceId, sidecarSource.kind),
|
|
28504
28944
|
moduleSideEffects: "no-treeshake"
|
|
28505
28945
|
};
|
|
28506
28946
|
};
|
|
@@ -28512,7 +28952,7 @@ function createLogicalEntryLoadHook(state) {
|
|
|
28512
28952
|
state.ctx.moduleGraphService.bindPluginContext(this);
|
|
28513
28953
|
if (state.ctx.configService.isDev) await state.loadEntry.call(this, logicalEntry.sourceId, logicalEntry.type === "app" ? "app" : logicalEntry.type === "page" ? "page" : "component");
|
|
28514
28954
|
return {
|
|
28515
|
-
code: createLogicalEntryModuleCode(logicalEntry, await collectLogicalEntryDependencies(state, logicalEntry.sourceId)),
|
|
28955
|
+
code: createLogicalEntryModuleCode(logicalEntry, await collectLogicalEntryDependencies(state, this, logicalEntry.sourceId)),
|
|
28516
28956
|
moduleSideEffects: "no-treeshake"
|
|
28517
28957
|
};
|
|
28518
28958
|
}
|
|
@@ -30121,6 +30561,11 @@ async function emitCompiledEntryBundleAssets(options) {
|
|
|
30121
30561
|
const style = await processVueResultStyle(sfcStyle, options.configService);
|
|
30122
30562
|
emitSfcStyleIfMissing(options.pluginCtx, options.bundle, options.relativeBase, style, options.outputExtensions.wxss, isAppVue ? { updateExisting: false } : void 0);
|
|
30123
30563
|
}
|
|
30564
|
+
const finalizeJsonConfig = isAppVue ? (config) => finalizeAppConfigForBuild(config, {
|
|
30565
|
+
buildScope: options.configService.weappViteConfig?.buildScope,
|
|
30566
|
+
platform: options.configService.platform,
|
|
30567
|
+
routeRules: options.configService.weappViteConfig?.routeRules
|
|
30568
|
+
}) : void 0;
|
|
30124
30569
|
if (options.result.config || shouldEmitComponentJson) emitSharedVueEntryJsonAsset({
|
|
30125
30570
|
bundle: options.bundle,
|
|
30126
30571
|
pluginCtx: options.pluginCtx,
|
|
@@ -30133,6 +30578,7 @@ async function emitCompiledEntryBundleAssets(options) {
|
|
|
30133
30578
|
mergeExistingAsset: shouldMergeJsonAsset,
|
|
30134
30579
|
mergeStrategy: jsonConfig?.mergeStrategy,
|
|
30135
30580
|
defaults: jsonConfig?.defaults?.[jsonKind],
|
|
30581
|
+
...finalizeJsonConfig ? { finalizeConfig: finalizeJsonConfig } : {},
|
|
30136
30582
|
kind: jsonKind,
|
|
30137
30583
|
extension: options.jsonExtension
|
|
30138
30584
|
}
|
|
@@ -30147,8 +30593,8 @@ async function emitCompiledEntryBundleAssets(options) {
|
|
|
30147
30593
|
function hasVueExtension(id) {
|
|
30148
30594
|
return Boolean(id?.endsWith(".vue"));
|
|
30149
30595
|
}
|
|
30150
|
-
function getCompileVueFileOptionsCacheKey(vuePath, isPage, isApp, delegatesComponentRegistration = false) {
|
|
30151
|
-
return `${vuePath}::${isPage ? "page" : "component"}::${isApp ? "app" : "entry"}::${delegatesComponentRegistration ? "logical-registration" : "module-registration"}`;
|
|
30596
|
+
function getCompileVueFileOptionsCacheKey(vuePath, isPage, isApp, delegatesComponentRegistration = false, emitResolvedComponentEntries = true) {
|
|
30597
|
+
return `${vuePath}::${isPage ? "page" : "component"}::${isApp ? "app" : "entry"}::${delegatesComponentRegistration ? "logical-registration" : "module-registration"}::${emitResolvedComponentEntries ? "emit-entries" : "resolve-only"}`;
|
|
30152
30598
|
}
|
|
30153
30599
|
function shouldDelegateComponentRegistration(ctx, vuePath, isPage, isApp, configService) {
|
|
30154
30600
|
return !isPage && !isApp && !configService.weappLibConfig?.enabled && !ctx.moduleGraphService?.isLogicalLayoutEntry?.(vuePath);
|
|
@@ -30178,6 +30624,24 @@ function resolveVueTemplatePlatformOptions(options) {
|
|
|
30178
30624
|
function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, configService, state, delegatesComponentRegistration) {
|
|
30179
30625
|
const importerBaseName = removeExtensionDeep(vuePath);
|
|
30180
30626
|
const autoImportResolveCache = /* @__PURE__ */ new Map();
|
|
30627
|
+
const resolveUsingComponentPath = createUsingComponentPathResolver(pluginCtx, configService, state.reExportResolutionCache);
|
|
30628
|
+
const externalComponentEntryMap = ctx.runtimeState?.build?.hmr?.externalComponentEntryMap;
|
|
30629
|
+
const registerResolvedComponentEntry = externalComponentEntryMap ? async (...args) => {
|
|
30630
|
+
const [importSource, importerFilename, info] = args;
|
|
30631
|
+
const resolved = await resolveUsingComponentPath(importSource, importerFilename, info);
|
|
30632
|
+
if (typeof resolved !== "string" && resolved?.from && resolved.resolvedId) {
|
|
30633
|
+
const outputKey = removeExtensionDeep(resolved.from).replace(/^\/+/, "");
|
|
30634
|
+
const isNewEntry = externalComponentEntryMap.get(outputKey) !== resolved.resolvedId;
|
|
30635
|
+
externalComponentEntryMap.set(outputKey, resolved.resolvedId);
|
|
30636
|
+
if (isNewEntry && state.emitResolvedComponentEntries !== false && typeof pluginCtx.emitFile === "function") pluginCtx.emitFile({
|
|
30637
|
+
type: "chunk",
|
|
30638
|
+
id: createLogicalEntryId(resolved.resolvedId, "component"),
|
|
30639
|
+
fileName: resolveRelativeOutputFileNameWithExtension(configService, resolved.resolvedId, ".js"),
|
|
30640
|
+
preserveSignature: "exports-only"
|
|
30641
|
+
});
|
|
30642
|
+
}
|
|
30643
|
+
return resolved;
|
|
30644
|
+
} : resolveUsingComponentPath;
|
|
30181
30645
|
const scopedSlotsCompiler = configService.weappViteConfig?.vue?.template?.scopedSlotsCompiler ?? "auto";
|
|
30182
30646
|
const scopedSlotsRequireProps = configService.weappViteConfig?.vue?.template?.scopedSlotsRequireProps ?? false;
|
|
30183
30647
|
const slotSingleRootNoWrapper = configService.weappViteConfig?.vue?.template?.slotSingleRootNoWrapper ?? false;
|
|
@@ -30273,7 +30737,7 @@ function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, conf
|
|
|
30273
30737
|
autoUsingComponents: {
|
|
30274
30738
|
enabled: true,
|
|
30275
30739
|
warn: (message) => logger_default.warn(message),
|
|
30276
|
-
resolveUsingComponentPath:
|
|
30740
|
+
resolveUsingComponentPath: registerResolvedComponentEntry
|
|
30277
30741
|
},
|
|
30278
30742
|
autoImportTags: {
|
|
30279
30743
|
enabled: true,
|
|
@@ -30331,7 +30795,7 @@ function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, conf
|
|
|
30331
30795
|
}
|
|
30332
30796
|
function createCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, configService, state) {
|
|
30333
30797
|
const delegatesComponentRegistration = shouldDelegateComponentRegistration(ctx, vuePath, isPage, isApp, configService);
|
|
30334
|
-
const cacheKey = getCompileVueFileOptionsCacheKey(vuePath, isPage, isApp, delegatesComponentRegistration);
|
|
30798
|
+
const cacheKey = getCompileVueFileOptionsCacheKey(vuePath, isPage, isApp, delegatesComponentRegistration, state.emitResolvedComponentEntries !== false);
|
|
30335
30799
|
const cached = state.compileOptionsCache?.get(cacheKey);
|
|
30336
30800
|
if (cached) return cached;
|
|
30337
30801
|
const created = buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, configService, state, delegatesComponentRegistration);
|
|
@@ -31416,7 +31880,8 @@ async function emitCompiledVueEntryAssets(bundle, state, filename, cached) {
|
|
|
31416
31880
|
reExportResolutionCache,
|
|
31417
31881
|
classStyleRuntimeWarned,
|
|
31418
31882
|
compileOptionsCache,
|
|
31419
|
-
componentMetaCache
|
|
31883
|
+
componentMetaCache,
|
|
31884
|
+
emitResolvedComponentEntries: false
|
|
31420
31885
|
};
|
|
31421
31886
|
const { outputExtensions, templateExtension, jsonExtension, scriptExtension, scriptModuleExtension, platformAssetOptions } = resolveVueBundleAssetContext(configService);
|
|
31422
31887
|
const emitState = await resolveCompiledEntryEmitState({
|
|
@@ -31537,7 +32002,8 @@ async function emitFallbackPageAssets(bundle, state, options) {
|
|
|
31537
32002
|
reExportResolutionCache,
|
|
31538
32003
|
classStyleRuntimeWarned,
|
|
31539
32004
|
compileOptionsCache,
|
|
31540
|
-
componentMetaCache
|
|
32005
|
+
componentMetaCache,
|
|
32006
|
+
emitResolvedComponentEntries: false
|
|
31541
32007
|
};
|
|
31542
32008
|
const { outputExtensions, templateExtension, styleExtension, jsonExtension, scriptModuleExtension, platformAssetOptions } = resolveVueBundleAssetContext(configService);
|
|
31543
32009
|
const collectedEntries = await collectFallbackPageEntryIds(configService, scanService);
|
|
@@ -33531,7 +33997,7 @@ async function loadAppEntry(ctx, scanState) {
|
|
|
33531
33997
|
const { path: appEntryPath } = appEntry;
|
|
33532
33998
|
let configFromVue;
|
|
33533
33999
|
if (!appConfigFile && vueAppPath) {
|
|
33534
|
-
const { extractConfigFromVue } = await import("./file-
|
|
34000
|
+
const { extractConfigFromVue } = await import("./file-BjrPjC70.mjs");
|
|
33535
34001
|
configFromVue = await extractConfigFromVue(vueAppPath);
|
|
33536
34002
|
if (configFromVue) appConfigFile = vueAppPath;
|
|
33537
34003
|
}
|
|
@@ -33553,9 +34019,12 @@ async function loadAppEntry(ctx, scanState) {
|
|
|
33553
34019
|
if (configFromVue) config = configFromVue;
|
|
33554
34020
|
else config = await ctx.jsonService.read(appConfigFile);
|
|
33555
34021
|
await applyAutoRoutesToAppConfigIfNeeded(ctx, config);
|
|
33556
|
-
|
|
34022
|
+
config = finalizeAppConfigForBuild(config, {
|
|
34023
|
+
buildScope: ctx.configService.weappViteConfig.buildScope,
|
|
34024
|
+
platform: ctx.configService.platform,
|
|
34025
|
+
routeRules: ctx.configService.weappViteConfig.routeRules
|
|
34026
|
+
});
|
|
33557
34027
|
if (isObject(config)) {
|
|
33558
|
-
normalizeAppConfigSubPackages(config);
|
|
33559
34028
|
const resolvedAppEntry = {
|
|
33560
34029
|
path: appEntryPath || vueAppPath,
|
|
33561
34030
|
preludePath: appPreludePath,
|
|
@@ -34509,4 +34978,4 @@ async function createCompilerContext(options) {
|
|
|
34509
34978
|
return ctx;
|
|
34510
34979
|
}
|
|
34511
34980
|
//#endregion
|
|
34512
|
-
export {
|
|
34981
|
+
export { isPathInside as A, findPreloadRuleKey as C, createCjsConfigLoadError as D, parseCommentJson as E, getDefaultIdeProjectRoot as O, collectPreloadPages as S, loadViteConfigFile 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, shouldPassPlatformArgToIdeOpen 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, suggestPreloadRules as w, getProjectConfigFileName as x, resolveWeappConfigFile as y };
|