weapp-vite 5.7.0 → 5.7.1

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/dist/cli.cjs CHANGED
@@ -1,6 +1,6 @@
1
- "use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
1
+ "use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkVRKZFXIZcjs = require('./chunk-VRKZFXIZ.cjs');
3
+ var _chunkGGLONZVQcjs = require('./chunk-GGLONZVQ.cjs');
4
4
 
5
5
 
6
6
 
@@ -11,7 +11,8 @@ var _chunkVRKZFXIZcjs = require('./chunk-VRKZFXIZ.cjs');
11
11
 
12
12
 
13
13
 
14
- var _chunkFUJ4D6IRcjs = require('./chunk-FUJ4D6IR.cjs');
14
+ var _chunkT4OVF4GPcjs = require('./chunk-T4OVF4GP.cjs');
15
+
15
16
 
16
17
 
17
18
  var _chunkA5DD7GKXcjs = require('./chunk-A5DD7GKX.cjs');
@@ -617,7 +618,7 @@ var _buffer = require('buffer');
617
618
 
618
619
  var _vite = require('vite');
619
620
  var VIRTUAL_MODULE_INDICATOR = "\0";
620
- var VIRTUAL_PREFIX = `${_chunkFUJ4D6IRcjs.SHARED_CHUNK_VIRTUAL_PREFIX}/`;
621
+ var VIRTUAL_PREFIX = `${_chunkT4OVF4GPcjs.SHARED_CHUNK_VIRTUAL_PREFIX}/`;
621
622
  function isPathInside(parent, candidate) {
622
623
  if (!parent) {
623
624
  return false;
@@ -980,7 +981,7 @@ async function analyzeSubpackages(ctx) {
980
981
  };
981
982
  const analysisConfig = configService.merge(
982
983
  void 0,
983
- _chunkFUJ4D6IRcjs.createSharedBuildConfig.call(void 0, configService, scanService),
984
+ _chunkT4OVF4GPcjs.createSharedBuildConfig.call(void 0, configService, scanService),
984
985
  {
985
986
  build: {
986
987
  write: false,
@@ -1007,6 +1008,125 @@ async function analyzeSubpackages(ctx) {
1007
1008
  };
1008
1009
  }
1009
1010
 
1011
+ // src/cli/analyze/dashboard.ts
1012
+ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
1013
+ var _path = require('path');
1014
+
1015
+ var _url = require('url');
1016
+
1017
+
1018
+ var __filename = _url.fileURLToPath.call(void 0, _chunkA5DD7GKXcjs.importMetaUrl);
1019
+ var __dirname = _path.dirname.call(void 0, __filename);
1020
+ var PACKAGE_ROOT = _path.resolve.call(void 0, __dirname, "../../..");
1021
+ var BUILD_DASHBOARD_ROOT = _path.resolve.call(void 0, PACKAGE_ROOT, "modules/analyze-dashboard");
1022
+ var ANALYZE_GLOBAL_KEY = "__WEAPP_VITE_ANALYZE_RESULT__";
1023
+ function resolveDashboardRoot() {
1024
+ if (_fsextra2.default.existsSync(BUILD_DASHBOARD_ROOT)) {
1025
+ return {
1026
+ root: BUILD_DASHBOARD_ROOT
1027
+ };
1028
+ }
1029
+ throw new Error(
1030
+ "[weapp-vite analyze] \u672A\u627E\u5230\u4EEA\u8868\u76D8\u4EA7\u7269\uFF0C\u8BF7\u5148\u6267\u884C `pnpm --filter weapp-vite run build:dashboard` \u751F\u6210\u3002"
1031
+ );
1032
+ }
1033
+ function createAnalyzeHtmlPlugin(state, onServerInstance) {
1034
+ return {
1035
+ name: "weapp-vite-analyze-html",
1036
+ transformIndexHtml(html) {
1037
+ return {
1038
+ html,
1039
+ tags: [
1040
+ {
1041
+ tag: "script",
1042
+ children: `window.${ANALYZE_GLOBAL_KEY} = ${JSON.stringify(state.current)}`,
1043
+ injectTo: "head-prepend"
1044
+ }
1045
+ ]
1046
+ };
1047
+ },
1048
+ configureServer(server) {
1049
+ onServerInstance(server);
1050
+ }
1051
+ };
1052
+ }
1053
+ async function waitForServerExit(server) {
1054
+ let resolved = false;
1055
+ const cleanup = async () => {
1056
+ if (resolved) {
1057
+ return;
1058
+ }
1059
+ resolved = true;
1060
+ try {
1061
+ await server.close();
1062
+ } catch (error) {
1063
+ _chunkT4OVF4GPcjs.logger_default.error(error);
1064
+ }
1065
+ };
1066
+ const signals = ["SIGINT", "SIGTERM"];
1067
+ await new Promise((resolvePromise) => {
1068
+ const resolveOnce = async () => {
1069
+ await cleanup();
1070
+ signals.forEach((signal) => {
1071
+ _process2.default.removeListener(signal, resolveOnce);
1072
+ });
1073
+ resolvePromise();
1074
+ };
1075
+ signals.forEach((signal) => {
1076
+ _process2.default.once(signal, resolveOnce);
1077
+ });
1078
+ _optionalChain([server, 'access', _5 => _5.httpServer, 'optionalAccess', _6 => _6.once, 'call', _7 => _7("close", resolveOnce)]);
1079
+ });
1080
+ }
1081
+ async function startAnalyzeDashboard(result, options) {
1082
+ const { root } = resolveDashboardRoot();
1083
+ const state = { current: result };
1084
+ let serverRef;
1085
+ const plugins = [
1086
+ createAnalyzeHtmlPlugin(state, (server2) => {
1087
+ serverRef = server2;
1088
+ })
1089
+ ];
1090
+ const server = await _vite.createServer.call(void 0, {
1091
+ root,
1092
+ clearScreen: false,
1093
+ appType: "spa",
1094
+ publicDir: false,
1095
+ plugins,
1096
+ server: {
1097
+ host: "127.0.0.1",
1098
+ port: 0
1099
+ },
1100
+ logLevel: "error"
1101
+ });
1102
+ await server.listen();
1103
+ serverRef ??= server;
1104
+ server.printUrls();
1105
+ _chunkT4OVF4GPcjs.logger_default.info("\u5206\u6790\u4EEA\u8868\u76D8\u5DF2\u542F\u52A8\uFF08\u4F7F\u7528\u9884\u6784\u5EFA\u8D44\u6E90\uFF09\uFF0C\u6309 Ctrl+C \u9000\u51FA\u3002");
1106
+ const waitPromise = waitForServerExit(server);
1107
+ const handle = {
1108
+ async update(nextResult) {
1109
+ state.current = nextResult;
1110
+ if (serverRef) {
1111
+ serverRef.ws.send({
1112
+ type: "custom",
1113
+ event: "weapp-analyze:update",
1114
+ data: nextResult
1115
+ });
1116
+ }
1117
+ },
1118
+ waitForExit: () => waitPromise,
1119
+ close: async () => {
1120
+ await server.close();
1121
+ }
1122
+ };
1123
+ if (_optionalChain([options, 'optionalAccess', _8 => _8.watch])) {
1124
+ void waitPromise;
1125
+ return handle;
1126
+ }
1127
+ await waitPromise;
1128
+ }
1129
+
1010
1130
  // src/cli/options.ts
1011
1131
  _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
1012
1132
  function filterDuplicateOptions(options) {
@@ -1059,7 +1179,7 @@ function coerceBooleanOption(value) {
1059
1179
  // src/cli/runtime.ts
1060
1180
  _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
1061
1181
  function logRuntimeTarget(targets) {
1062
- _chunkFUJ4D6IRcjs.logger_default.info(`\u76EE\u6807\u5E73\u53F0\uFF1A${targets.label}`);
1182
+ _chunkT4OVF4GPcjs.logger_default.info(`\u76EE\u6807\u5E73\u53F0\uFF1A${targets.label}`);
1063
1183
  }
1064
1184
  function resolveRuntimeTargets(options) {
1065
1185
  const rawPlatform = typeof options.platform === "string" ? options.platform : typeof options.p === "string" ? options.p : void 0;
@@ -1067,17 +1187,17 @@ function resolveRuntimeTargets(options) {
1067
1187
  return {
1068
1188
  runMini: true,
1069
1189
  runWeb: false,
1070
- mpPlatform: _chunkFUJ4D6IRcjs.DEFAULT_MP_PLATFORM,
1071
- label: _chunkFUJ4D6IRcjs.DEFAULT_MP_PLATFORM
1190
+ mpPlatform: _chunkT4OVF4GPcjs.DEFAULT_MP_PLATFORM,
1191
+ label: _chunkT4OVF4GPcjs.DEFAULT_MP_PLATFORM
1072
1192
  };
1073
1193
  }
1074
- const normalized = _chunkFUJ4D6IRcjs.normalizeMiniPlatform.call(void 0, rawPlatform);
1194
+ const normalized = _chunkT4OVF4GPcjs.normalizeMiniPlatform.call(void 0, rawPlatform);
1075
1195
  if (!normalized) {
1076
1196
  return {
1077
1197
  runMini: true,
1078
1198
  runWeb: false,
1079
- mpPlatform: _chunkFUJ4D6IRcjs.DEFAULT_MP_PLATFORM,
1080
- label: _chunkFUJ4D6IRcjs.DEFAULT_MP_PLATFORM
1199
+ mpPlatform: _chunkT4OVF4GPcjs.DEFAULT_MP_PLATFORM,
1200
+ label: _chunkT4OVF4GPcjs.DEFAULT_MP_PLATFORM
1081
1201
  };
1082
1202
  }
1083
1203
  if (normalized === "h5" || normalized === "web") {
@@ -1088,7 +1208,7 @@ function resolveRuntimeTargets(options) {
1088
1208
  label: normalized === "h5" ? "h5" : "web"
1089
1209
  };
1090
1210
  }
1091
- const mpPlatform = _chunkFUJ4D6IRcjs.resolveMiniPlatform.call(void 0, normalized);
1211
+ const mpPlatform = _chunkT4OVF4GPcjs.resolveMiniPlatform.call(void 0, normalized);
1092
1212
  if (mpPlatform) {
1093
1213
  return {
1094
1214
  runMini: true,
@@ -1097,12 +1217,12 @@ function resolveRuntimeTargets(options) {
1097
1217
  label: mpPlatform
1098
1218
  };
1099
1219
  }
1100
- _chunkFUJ4D6IRcjs.logger_default.warn(`\u672A\u8BC6\u522B\u7684\u5E73\u53F0 "${rawPlatform}"\uFF0C\u5DF2\u56DE\u9000\u5230 ${_chunkFUJ4D6IRcjs.DEFAULT_MP_PLATFORM}`);
1220
+ _chunkT4OVF4GPcjs.logger_default.warn(`\u672A\u8BC6\u522B\u7684\u5E73\u53F0 "${rawPlatform}"\uFF0C\u5DF2\u56DE\u9000\u5230 ${_chunkT4OVF4GPcjs.DEFAULT_MP_PLATFORM}`);
1101
1221
  return {
1102
1222
  runMini: true,
1103
1223
  runWeb: false,
1104
- mpPlatform: _chunkFUJ4D6IRcjs.DEFAULT_MP_PLATFORM,
1105
- label: _chunkFUJ4D6IRcjs.DEFAULT_MP_PLATFORM
1224
+ mpPlatform: _chunkT4OVF4GPcjs.DEFAULT_MP_PLATFORM,
1225
+ label: _chunkT4OVF4GPcjs.DEFAULT_MP_PLATFORM
1106
1226
  };
1107
1227
  }
1108
1228
  function createInlineConfig(mpPlatform) {
@@ -1130,15 +1250,15 @@ function printAnalysisSummary(result) {
1130
1250
  packageModuleSet.set(pkgRef.packageId, set);
1131
1251
  }
1132
1252
  }
1133
- _chunkFUJ4D6IRcjs.logger_default.success("\u5206\u5305\u5206\u6790\u5B8C\u6210");
1253
+ _chunkT4OVF4GPcjs.logger_default.success("\u5206\u5305\u5206\u6790\u5B8C\u6210");
1134
1254
  for (const pkg of result.packages) {
1135
1255
  const chunkCount = pkg.files.filter((file) => file.type === "chunk").length;
1136
1256
  const assetCount = pkg.files.length - chunkCount;
1137
- const moduleCount = _nullishCoalesce(_optionalChain([packageModuleSet, 'access', _5 => _5.get, 'call', _6 => _6(pkg.id), 'optionalAccess', _7 => _7.size]), () => ( 0));
1138
- _chunkFUJ4D6IRcjs.logger_default.info(`- ${pkg.label}\uFF1A${chunkCount} \u4E2A\u6A21\u5757\u4EA7\u7269\uFF0C${assetCount} \u4E2A\u8D44\u6E90\uFF0C\u8986\u76D6 ${moduleCount} \u4E2A\u6E90\u7801\u6A21\u5757`);
1257
+ const moduleCount = _nullishCoalesce(_optionalChain([packageModuleSet, 'access', _9 => _9.get, 'call', _10 => _10(pkg.id), 'optionalAccess', _11 => _11.size]), () => ( 0));
1258
+ _chunkT4OVF4GPcjs.logger_default.info(`- ${pkg.label}\uFF1A${chunkCount} \u4E2A\u6A21\u5757\u4EA7\u7269\uFF0C${assetCount} \u4E2A\u8D44\u6E90\uFF0C\u8986\u76D6 ${moduleCount} \u4E2A\u6E90\u7801\u6A21\u5757`);
1139
1259
  }
1140
1260
  if (result.subPackages.length > 0) {
1141
- _chunkFUJ4D6IRcjs.logger_default.info("\u5206\u5305\u914D\u7F6E\uFF1A");
1261
+ _chunkT4OVF4GPcjs.logger_default.info("\u5206\u5305\u914D\u7F6E\uFF1A");
1142
1262
  for (const descriptor of result.subPackages) {
1143
1263
  const segments = [descriptor.root];
1144
1264
  if (descriptor.name) {
@@ -1147,15 +1267,15 @@ function printAnalysisSummary(result) {
1147
1267
  if (descriptor.independent) {
1148
1268
  segments.push("\u72EC\u7ACB\u6784\u5EFA");
1149
1269
  }
1150
- _chunkFUJ4D6IRcjs.logger_default.info(`- ${segments.join("\uFF0C")}`);
1270
+ _chunkT4OVF4GPcjs.logger_default.info(`- ${segments.join("\uFF0C")}`);
1151
1271
  }
1152
1272
  }
1153
1273
  const duplicates = result.modules.filter((module) => module.packages.length > 1);
1154
1274
  if (duplicates.length === 0) {
1155
- _chunkFUJ4D6IRcjs.logger_default.info("\u672A\u68C0\u6D4B\u5230\u8DE8\u5305\u590D\u7528\u7684\u6E90\u7801\u6A21\u5757\u3002");
1275
+ _chunkT4OVF4GPcjs.logger_default.info("\u672A\u68C0\u6D4B\u5230\u8DE8\u5305\u590D\u7528\u7684\u6E90\u7801\u6A21\u5757\u3002");
1156
1276
  return;
1157
1277
  }
1158
- _chunkFUJ4D6IRcjs.logger_default.info(`\u8DE8\u5305\u590D\u7528/\u590D\u5236\u6E90\u7801\u5171 ${duplicates.length} \u9879\uFF1A`);
1278
+ _chunkT4OVF4GPcjs.logger_default.info(`\u8DE8\u5305\u590D\u7528/\u590D\u5236\u6E90\u7801\u5171 ${duplicates.length} \u9879\uFF1A`);
1159
1279
  const limit = 10;
1160
1280
  const entries = duplicates.slice(0, limit);
1161
1281
  for (const module of entries) {
@@ -1163,10 +1283,10 @@ function printAnalysisSummary(result) {
1163
1283
  const label = _nullishCoalesce(packageLabelMap.get(pkgRef.packageId), () => ( pkgRef.packageId));
1164
1284
  return `${label} \u2192 ${pkgRef.files.join(", ")}`;
1165
1285
  }).join("\uFF1B");
1166
- _chunkFUJ4D6IRcjs.logger_default.info(`- ${module.source} (${module.sourceType})\uFF1A${placements}`);
1286
+ _chunkT4OVF4GPcjs.logger_default.info(`- ${module.source} (${module.sourceType})\uFF1A${placements}`);
1167
1287
  }
1168
1288
  if (duplicates.length > limit) {
1169
- _chunkFUJ4D6IRcjs.logger_default.info(`- \u2026\u5176\u4F59 ${duplicates.length - limit} \u9879\u8BF7\u4F7F\u7528 \`weapp-vite analyze --json\` \u67E5\u770B`);
1289
+ _chunkT4OVF4GPcjs.logger_default.info(`- \u2026\u5176\u4F59 ${duplicates.length - limit} \u9879\u8BF7\u4F7F\u7528 \`weapp-vite analyze --json\` \u67E5\u770B`);
1170
1290
  }
1171
1291
  }
1172
1292
  function registerAnalyzeCommand(cli2) {
@@ -1176,15 +1296,15 @@ function registerAnalyzeCommand(cli2) {
1176
1296
  const targets = resolveRuntimeTargets(options);
1177
1297
  logRuntimeTarget(targets);
1178
1298
  if (!targets.runMini) {
1179
- _chunkFUJ4D6IRcjs.logger_default.warn("\u5F53\u524D\u547D\u4EE4\u4EC5\u652F\u6301\u5C0F\u7A0B\u5E8F\u5E73\u53F0\uFF0C\u8BF7\u901A\u8FC7 --platform weapp \u6307\u5B9A\u76EE\u6807\u3002");
1299
+ _chunkT4OVF4GPcjs.logger_default.warn("\u5F53\u524D\u547D\u4EE4\u4EC5\u652F\u6301\u5C0F\u7A0B\u5E8F\u5E73\u53F0\uFF0C\u8BF7\u901A\u8FC7 --platform weapp \u6307\u5B9A\u76EE\u6807\u3002");
1180
1300
  return;
1181
1301
  }
1182
1302
  if (targets.runWeb) {
1183
- _chunkFUJ4D6IRcjs.logger_default.warn("\u5206\u6790\u547D\u4EE4\u6682\u4E0D\u652F\u6301 Web \u5E73\u53F0\uFF0C\u5C06\u5FFD\u7565\u76F8\u5173\u914D\u7F6E\u3002");
1303
+ _chunkT4OVF4GPcjs.logger_default.warn("\u5206\u6790\u547D\u4EE4\u6682\u4E0D\u652F\u6301 Web \u5E73\u53F0\uFF0C\u5C06\u5FFD\u7565\u76F8\u5173\u914D\u7F6E\u3002");
1184
1304
  }
1185
1305
  const inlineConfig = createInlineConfig(targets.mpPlatform);
1186
1306
  try {
1187
- const ctx = await _chunkVRKZFXIZcjs.createCompilerContext.call(void 0, {
1307
+ const ctx = await _chunkGGLONZVQcjs.createCompilerContext.call(void 0, {
1188
1308
  cwd: root,
1189
1309
  mode: _nullishCoalesce(options.mode, () => ( "production")),
1190
1310
  configFile,
@@ -1196,13 +1316,13 @@ function registerAnalyzeCommand(cli2) {
1196
1316
  let writtenPath;
1197
1317
  if (outputOption) {
1198
1318
  const configService = ctx.configService;
1199
- const baseDir = _nullishCoalesce(_optionalChain([configService, 'optionalAccess', _8 => _8.cwd]), () => ( _process2.default.cwd()));
1319
+ const baseDir = _nullishCoalesce(_optionalChain([configService, 'optionalAccess', _12 => _12.cwd]), () => ( _process2.default.cwd()));
1200
1320
  const resolvedOutputPath = _pathe2.default.isAbsolute(outputOption) ? outputOption : _pathe2.default.resolve(baseDir, outputOption);
1201
1321
  await _fsextra2.default.ensureDir(_pathe2.default.dirname(resolvedOutputPath));
1202
1322
  await _fsextra2.default.writeFile(resolvedOutputPath, `${JSON.stringify(result, null, 2)}
1203
1323
  `, "utf8");
1204
1324
  const relativeOutput = configService ? configService.relativeCwd(resolvedOutputPath) : resolvedOutputPath;
1205
- _chunkFUJ4D6IRcjs.logger_default.success(`\u5206\u6790\u7ED3\u679C\u5DF2\u5199\u5165 ${relativeOutput}`);
1325
+ _chunkT4OVF4GPcjs.logger_default.success(`\u5206\u6790\u7ED3\u679C\u5DF2\u5199\u5165 ${relativeOutput}`);
1206
1326
  writtenPath = resolvedOutputPath;
1207
1327
  }
1208
1328
  if (outputJson) {
@@ -1212,9 +1332,10 @@ function registerAnalyzeCommand(cli2) {
1212
1332
  }
1213
1333
  } else {
1214
1334
  printAnalysisSummary(result);
1335
+ await startAnalyzeDashboard(result);
1215
1336
  }
1216
1337
  } catch (error) {
1217
- _chunkFUJ4D6IRcjs.logger_default.error(error);
1338
+ _chunkT4OVF4GPcjs.logger_default.error(error);
1218
1339
  _process2.default.exitCode = 1;
1219
1340
  }
1220
1341
  });
@@ -1372,15 +1493,15 @@ function logBuildAppFinish(configService, webServer, options = {}) {
1372
1493
  const urls = webServer.resolvedUrls;
1373
1494
  const candidates = urls ? [..._nullishCoalesce(urls.local, () => ( [])), ..._nullishCoalesce(urls.network, () => ( []))] : [];
1374
1495
  if (candidates.length > 0) {
1375
- _chunkFUJ4D6IRcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
1496
+ _chunkT4OVF4GPcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
1376
1497
  for (const url of candidates) {
1377
- _chunkFUJ4D6IRcjs.logger_default.info(` \u279C ${url}`);
1498
+ _chunkT4OVF4GPcjs.logger_default.info(` \u279C ${url}`);
1378
1499
  }
1379
1500
  } else {
1380
- _chunkFUJ4D6IRcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
1501
+ _chunkT4OVF4GPcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
1381
1502
  }
1382
1503
  } else {
1383
- _chunkFUJ4D6IRcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
1504
+ _chunkT4OVF4GPcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
1384
1505
  }
1385
1506
  logBuildAppFinishOnlyShowOnce = true;
1386
1507
  return;
@@ -1394,19 +1515,19 @@ function logBuildAppFinish(configService, webServer, options = {}) {
1394
1515
  args: ["run", "open"]
1395
1516
  }));
1396
1517
  const devCommand = `${command} ${args.join(" ")}`;
1397
- _chunkFUJ4D6IRcjs.logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
1398
- _chunkFUJ4D6IRcjs.logger_default.info(`\u6267\u884C \`${devCommand}\` \u53EF\u4EE5\u76F4\u63A5\u5728 \`\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\` \u91CC\u6253\u5F00\u5F53\u524D\u5E94\u7528`);
1399
- _chunkFUJ4D6IRcjs.logger_default.info("\u6216\u624B\u52A8\u6253\u5F00\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\uFF0C\u5BFC\u5165\u6839\u76EE\u5F55(`project.config.json` \u6587\u4EF6\u6240\u5728\u7684\u76EE\u5F55)\uFF0C\u5373\u53EF\u9884\u89C8\u6548\u679C");
1518
+ _chunkT4OVF4GPcjs.logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
1519
+ _chunkT4OVF4GPcjs.logger_default.info(`\u6267\u884C \`${devCommand}\` \u53EF\u4EE5\u76F4\u63A5\u5728 \`\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\` \u91CC\u6253\u5F00\u5F53\u524D\u5E94\u7528`);
1520
+ _chunkT4OVF4GPcjs.logger_default.info("\u6216\u624B\u52A8\u6253\u5F00\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\uFF0C\u5BFC\u5165\u6839\u76EE\u5F55(`project.config.json` \u6587\u4EF6\u6240\u5728\u7684\u76EE\u5F55)\uFF0C\u5373\u53EF\u9884\u89C8\u6548\u679C");
1400
1521
  if (!skipWeb && webServer) {
1401
1522
  const urls = webServer.resolvedUrls;
1402
1523
  const candidates = urls ? [..._nullishCoalesce(urls.local, () => ( [])), ..._nullishCoalesce(urls.network, () => ( []))] : [];
1403
1524
  if (candidates.length > 0) {
1404
- _chunkFUJ4D6IRcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
1525
+ _chunkT4OVF4GPcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
1405
1526
  for (const url of candidates) {
1406
- _chunkFUJ4D6IRcjs.logger_default.info(` \u279C ${url}`);
1527
+ _chunkT4OVF4GPcjs.logger_default.info(` \u279C ${url}`);
1407
1528
  }
1408
1529
  } else {
1409
- _chunkFUJ4D6IRcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
1530
+ _chunkT4OVF4GPcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
1410
1531
  }
1411
1532
  }
1412
1533
  logBuildAppFinishOnlyShowOnce = true;
@@ -1419,7 +1540,7 @@ async function openIde() {
1419
1540
  try {
1420
1541
  await _weappidecli.parse.call(void 0, ["open", "-p"]);
1421
1542
  } catch (error) {
1422
- _chunkFUJ4D6IRcjs.logger_default.error(error);
1543
+ _chunkT4OVF4GPcjs.logger_default.error(error);
1423
1544
  }
1424
1545
  }
1425
1546
 
@@ -1434,28 +1555,35 @@ function registerBuildCommand(cli2) {
1434
1555
  ).option(
1435
1556
  "--emptyOutDir",
1436
1557
  `[boolean] force empty outDir when it's outside of root`
1437
- ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).action(async (root, options) => {
1558
+ ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).option("--analyze", `[boolean] \u8F93\u51FA\u5206\u5305\u5206\u6790\u4EEA\u8868\u76D8`, { default: false }).action(async (root, options) => {
1438
1559
  filterDuplicateOptions(options);
1439
1560
  const configFile = resolveConfigFile(options);
1440
1561
  const targets = resolveRuntimeTargets(options);
1441
1562
  logRuntimeTarget(targets);
1442
1563
  const inlineConfig = createInlineConfig(targets.mpPlatform);
1443
- const { buildService, configService, webService } = await _chunkVRKZFXIZcjs.createCompilerContext.call(void 0, {
1564
+ const ctx = await _chunkGGLONZVQcjs.createCompilerContext.call(void 0, {
1444
1565
  cwd: root,
1445
1566
  mode: _nullishCoalesce(options.mode, () => ( "production")),
1446
1567
  configFile,
1447
1568
  inlineConfig
1448
1569
  });
1570
+ const { buildService, configService, webService } = ctx;
1571
+ const enableAnalyze = Boolean(options.analyze && targets.runMini);
1572
+ let analyzeHandle;
1449
1573
  if (targets.runMini) {
1450
1574
  await buildService.build(options);
1575
+ if (enableAnalyze) {
1576
+ const analyzeResult = await analyzeSubpackages(ctx);
1577
+ analyzeHandle = await _asyncNullishCoalesce(await startAnalyzeDashboard(analyzeResult, { watch: true }), async () => ( void 0));
1578
+ }
1451
1579
  }
1452
1580
  const webConfig = configService.weappWebConfig;
1453
- if (targets.runWeb && _optionalChain([webConfig, 'optionalAccess', _9 => _9.enabled])) {
1581
+ if (targets.runWeb && _optionalChain([webConfig, 'optionalAccess', _13 => _13.enabled])) {
1454
1582
  try {
1455
- await _optionalChain([webService, 'optionalAccess', _10 => _10.build, 'call', _11 => _11()]);
1456
- _chunkFUJ4D6IRcjs.logger_default.success(`Web \u6784\u5EFA\u5B8C\u6210\uFF0C\u8F93\u51FA\u76EE\u5F55\uFF1A${configService.relativeCwd(webConfig.outDir)}`);
1583
+ await _optionalChain([webService, 'optionalAccess', _14 => _14.build, 'call', _15 => _15()]);
1584
+ _chunkT4OVF4GPcjs.logger_default.success(`Web \u6784\u5EFA\u5B8C\u6210\uFF0C\u8F93\u51FA\u76EE\u5F55\uFF1A${configService.relativeCwd(webConfig.outDir)}`);
1457
1585
  } catch (error) {
1458
- _chunkFUJ4D6IRcjs.logger_default.error(error);
1586
+ _chunkT4OVF4GPcjs.logger_default.error(error);
1459
1587
  throw error;
1460
1588
  }
1461
1589
  }
@@ -1465,6 +1593,9 @@ function registerBuildCommand(cli2) {
1465
1593
  if (options.open && targets.runMini) {
1466
1594
  await openIde();
1467
1595
  }
1596
+ if (analyzeHandle) {
1597
+ await analyzeHandle.waitForExit();
1598
+ }
1468
1599
  });
1469
1600
  }
1470
1601
 
@@ -1524,11 +1655,11 @@ async function loadTemplate(template, context) {
1524
1655
  return void 0;
1525
1656
  }
1526
1657
  function resolveTemplate(templates, type, fileType) {
1527
- const scoped = _optionalChain([templates, 'optionalAccess', _12 => _12[type], 'optionalAccess', _13 => _13[fileType]]);
1658
+ const scoped = _optionalChain([templates, 'optionalAccess', _16 => _16[type], 'optionalAccess', _17 => _17[fileType]]);
1528
1659
  if (scoped !== void 0) {
1529
1660
  return scoped;
1530
1661
  }
1531
- return _optionalChain([templates, 'optionalAccess', _14 => _14.shared, 'optionalAccess', _15 => _15[fileType]]);
1662
+ return _optionalChain([templates, 'optionalAccess', _18 => _18.shared, 'optionalAccess', _19 => _19[fileType]]);
1532
1663
  }
1533
1664
  async function generate(options) {
1534
1665
  let { fileName, outDir, extensions, type, cwd, templates } = _shared.defu.call(void 0, options, {
@@ -1583,7 +1714,7 @@ async function generate(options) {
1583
1714
  for (const { code, fileName: fileName2 } of files) {
1584
1715
  if (code !== void 0) {
1585
1716
  await _fsextra2.default.outputFile(_pathe2.default.resolve(basepath, fileName2), code, "utf8");
1586
- _chunkFUJ4D6IRcjs.logger_default.success(`${composePath(outDir, fileName2)} \u521B\u5EFA\u6210\u529F\uFF01`);
1717
+ _chunkT4OVF4GPcjs.logger_default.success(`${composePath(outDir, fileName2)} \u521B\u5EFA\u6210\u529F\uFF01`);
1587
1718
  }
1588
1719
  }
1589
1720
  }
@@ -1605,14 +1736,14 @@ async function loadConfig(configFile) {
1605
1736
  mode: "development"
1606
1737
  };
1607
1738
  const loaded = await _vite.loadConfigFromFile.call(void 0, configEnv, resolvedConfigFile, cwd);
1608
- const weappConfigFilePath = await _chunkFUJ4D6IRcjs.resolveWeappConfigFile.call(void 0, {
1739
+ const weappConfigFilePath = await _chunkT4OVF4GPcjs.resolveWeappConfigFile.call(void 0, {
1609
1740
  root: cwd,
1610
1741
  specified: resolvedConfigFile
1611
1742
  });
1612
1743
  let weappLoaded;
1613
1744
  if (weappConfigFilePath) {
1614
1745
  const normalizedWeappPath = _pathe2.default.resolve(weappConfigFilePath);
1615
- const normalizedLoadedPath = _optionalChain([loaded, 'optionalAccess', _16 => _16.path]) ? _pathe2.default.resolve(loaded.path) : void 0;
1746
+ const normalizedLoadedPath = _optionalChain([loaded, 'optionalAccess', _20 => _20.path]) ? _pathe2.default.resolve(loaded.path) : void 0;
1616
1747
  if (normalizedLoadedPath && normalizedLoadedPath === normalizedWeappPath) {
1617
1748
  weappLoaded = loaded;
1618
1749
  } else {
@@ -1622,23 +1753,23 @@ async function loadConfig(configFile) {
1622
1753
  if (!loaded && !weappLoaded) {
1623
1754
  return void 0;
1624
1755
  }
1625
- const config = _nullishCoalesce(_optionalChain([loaded, 'optionalAccess', _17 => _17.config]), () => ( (_nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess', _18 => _18.config]), () => ( {})))));
1626
- if (_optionalChain([weappLoaded, 'optionalAccess', _19 => _19.config, 'optionalAccess', _20 => _20.weapp])) {
1756
+ const config = _nullishCoalesce(_optionalChain([loaded, 'optionalAccess', _21 => _21.config]), () => ( (_nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess', _22 => _22.config]), () => ( {})))));
1757
+ if (_optionalChain([weappLoaded, 'optionalAccess', _23 => _23.config, 'optionalAccess', _24 => _24.weapp])) {
1627
1758
  config.weapp = _shared.defu.call(void 0,
1628
1759
  weappLoaded.config.weapp,
1629
1760
  _nullishCoalesce(config.weapp, () => ( {}))
1630
1761
  );
1631
1762
  }
1632
1763
  const dependencySet = /* @__PURE__ */ new Set();
1633
- for (const dependency of _nullishCoalesce(_optionalChain([loaded, 'optionalAccess', _21 => _21.dependencies]), () => ( []))) {
1764
+ for (const dependency of _nullishCoalesce(_optionalChain([loaded, 'optionalAccess', _25 => _25.dependencies]), () => ( []))) {
1634
1765
  dependencySet.add(dependency);
1635
1766
  }
1636
- for (const dependency of _nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess', _22 => _22.dependencies]), () => ( []))) {
1767
+ for (const dependency of _nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess', _26 => _26.dependencies]), () => ( []))) {
1637
1768
  dependencySet.add(dependency);
1638
1769
  }
1639
1770
  return {
1640
1771
  config,
1641
- path: _nullishCoalesce(_nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess', _23 => _23.path]), () => ( _optionalChain([loaded, 'optionalAccess', _24 => _24.path]))), () => ( resolvedConfigFile)),
1772
+ path: _nullishCoalesce(_nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess', _27 => _27.path]), () => ( _optionalChain([loaded, 'optionalAccess', _28 => _28.path]))), () => ( resolvedConfigFile)),
1642
1773
  dependencies: Array.from(dependencySet)
1643
1774
  };
1644
1775
  }
@@ -1658,20 +1789,20 @@ function registerGenerateCommand(cli2) {
1658
1789
  fileName = "app";
1659
1790
  }
1660
1791
  if (filepath === void 0) {
1661
- _chunkFUJ4D6IRcjs.logger_default.error("weapp-vite generate <outDir> \u547D\u4EE4\u5FC5\u987B\u4F20\u5165\u8DEF\u5F84\u53C2\u6570 outDir");
1792
+ _chunkT4OVF4GPcjs.logger_default.error("weapp-vite generate <outDir> \u547D\u4EE4\u5FC5\u987B\u4F20\u5165\u8DEF\u5F84\u53C2\u6570 outDir");
1662
1793
  return;
1663
1794
  }
1664
1795
  if (options.page) {
1665
1796
  type = "page";
1666
1797
  }
1667
- const generateOptions = _optionalChain([config, 'optionalAccess', _25 => _25.config, 'access', _26 => _26.weapp, 'optionalAccess', _27 => _27.generate]);
1668
- fileName = _nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _28 => _28.filenames, 'optionalAccess', _29 => _29[type]]), () => ( fileName));
1798
+ const generateOptions = _optionalChain([config, 'optionalAccess', _29 => _29.config, 'access', _30 => _30.weapp, 'optionalAccess', _31 => _31.generate]);
1799
+ fileName = _nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _32 => _32.filenames, 'optionalAccess', _33 => _33[type]]), () => ( fileName));
1669
1800
  await generate({
1670
- outDir: _pathe2.default.join(_nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _30 => _30.dirs, 'optionalAccess', _31 => _31[type]]), () => ( "")), filepath),
1801
+ outDir: _pathe2.default.join(_nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _34 => _34.dirs, 'optionalAccess', _35 => _35[type]]), () => ( "")), filepath),
1671
1802
  type,
1672
1803
  fileName,
1673
- extensions: _optionalChain([generateOptions, 'optionalAccess', _32 => _32.extensions]),
1674
- templates: _optionalChain([generateOptions, 'optionalAccess', _33 => _33.templates])
1804
+ extensions: _optionalChain([generateOptions, 'optionalAccess', _36 => _36.extensions]),
1805
+ templates: _optionalChain([generateOptions, 'optionalAccess', _37 => _37.templates])
1675
1806
  });
1676
1807
  });
1677
1808
  }
@@ -1686,7 +1817,7 @@ function registerInitCommand(cli2) {
1686
1817
  command: "weapp-vite"
1687
1818
  });
1688
1819
  } catch (error) {
1689
- _chunkFUJ4D6IRcjs.logger_default.error(error);
1820
+ _chunkT4OVF4GPcjs.logger_default.error(error);
1690
1821
  }
1691
1822
  });
1692
1823
  }
@@ -1699,7 +1830,7 @@ function registerNpmCommand(cli2) {
1699
1830
  try {
1700
1831
  await _weappidecli.parse.call(void 0, ["build-npm", "-p"]);
1701
1832
  } catch (error) {
1702
- _chunkFUJ4D6IRcjs.logger_default.error(error);
1833
+ _chunkT4OVF4GPcjs.logger_default.error(error);
1703
1834
  }
1704
1835
  });
1705
1836
  }
@@ -1715,28 +1846,57 @@ function registerOpenCommand(cli2) {
1715
1846
  // src/cli/commands/serve.ts
1716
1847
  _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
1717
1848
  function registerServeCommand(cli2) {
1718
- cli2.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).action(async (root, options) => {
1849
+ cli2.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).option("--analyze", `[boolean] \u542F\u52A8\u5206\u5305\u5206\u6790\u4EEA\u8868\u76D8 (\u5B9E\u9A8C\u7279\u6027)`, { default: false }).action(async (root, options) => {
1719
1850
  filterDuplicateOptions(options);
1720
1851
  const configFile = resolveConfigFile(options);
1721
1852
  const targets = resolveRuntimeTargets(options);
1722
1853
  logRuntimeTarget(targets);
1723
1854
  const inlineConfig = createInlineConfig(targets.mpPlatform);
1724
- const { buildService, configService, webService } = await _chunkVRKZFXIZcjs.createCompilerContext.call(void 0, {
1855
+ const ctx = await _chunkGGLONZVQcjs.createCompilerContext.call(void 0, {
1725
1856
  cwd: root,
1726
1857
  mode: _nullishCoalesce(options.mode, () => ( "development")),
1727
1858
  isDev: true,
1728
1859
  configFile,
1729
1860
  inlineConfig
1730
1861
  });
1862
+ const { buildService, configService, webService } = ctx;
1863
+ const enableAnalyze = Boolean(options.analyze && targets.runMini);
1864
+ let analyzeHandle;
1865
+ const triggerAnalyzeUpdate = async () => {
1866
+ if (!analyzeHandle) {
1867
+ return;
1868
+ }
1869
+ const next = await analyzeSubpackages(ctx);
1870
+ await analyzeHandle.update(next);
1871
+ };
1731
1872
  if (targets.runMini) {
1732
- await buildService.build(options);
1873
+ const buildResult = await buildService.build(options);
1874
+ if (enableAnalyze) {
1875
+ const initialResult = await analyzeSubpackages(ctx);
1876
+ analyzeHandle = await _asyncNullishCoalesce(await startAnalyzeDashboard(initialResult, { watch: true }), async () => ( void 0));
1877
+ if (analyzeHandle && buildResult && typeof buildResult.on === "function") {
1878
+ const watcher = buildResult;
1879
+ let updating = false;
1880
+ watcher.on("event", (event) => {
1881
+ if (event.code !== "END" || updating) {
1882
+ return;
1883
+ }
1884
+ updating = true;
1885
+ triggerAnalyzeUpdate().finally(() => {
1886
+ updating = false;
1887
+ });
1888
+ });
1889
+ } else if (analyzeHandle) {
1890
+ await triggerAnalyzeUpdate();
1891
+ }
1892
+ }
1733
1893
  }
1734
1894
  let webServer;
1735
1895
  if (targets.runWeb) {
1736
1896
  try {
1737
- webServer = await _optionalChain([webService, 'optionalAccess', _34 => _34.startDevServer, 'call', _35 => _35()]);
1897
+ webServer = await _optionalChain([webService, 'optionalAccess', _38 => _38.startDevServer, 'call', _39 => _39()]);
1738
1898
  } catch (error) {
1739
- _chunkFUJ4D6IRcjs.logger_default.error(error);
1899
+ _chunkT4OVF4GPcjs.logger_default.error(error);
1740
1900
  throw error;
1741
1901
  }
1742
1902
  }
@@ -1748,13 +1908,16 @@ function registerServeCommand(cli2) {
1748
1908
  if (options.open && targets.runMini) {
1749
1909
  await openIde();
1750
1910
  }
1911
+ if (analyzeHandle) {
1912
+ await analyzeHandle.waitForExit();
1913
+ }
1751
1914
  });
1752
1915
  }
1753
1916
 
1754
1917
  // src/cli.ts
1755
1918
  var cli = cac("weapp-vite");
1756
1919
  try {
1757
- _chunkFUJ4D6IRcjs.checkRuntime.call(void 0, {
1920
+ _chunkT4OVF4GPcjs.checkRuntime.call(void 0, {
1758
1921
  bun: "0.0.0",
1759
1922
  deno: "0.0.0",
1760
1923
  node: "20.19.0"
@@ -1773,5 +1936,5 @@ registerNpmCommand(cli);
1773
1936
  registerGenerateCommand(cli);
1774
1937
  registerCreateCommand(cli);
1775
1938
  cli.help();
1776
- cli.version(_chunkFUJ4D6IRcjs.VERSION);
1939
+ cli.version(_chunkT4OVF4GPcjs.VERSION);
1777
1940
  cli.parse();