weapp-vite 5.3.0 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -1,10 +1,15 @@
1
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; }
2
2
 
3
+ var _chunkLX2OMRQ4cjs = require('./chunk-LX2OMRQ4.cjs');
3
4
 
4
5
 
5
6
 
6
7
 
7
- var _chunkN2SUN4MXcjs = require('./chunk-N2SUN4MX.cjs');
8
+
9
+
10
+
11
+
12
+ var _chunkXEHEGODScjs = require('./chunk-XEHEGODS.cjs');
8
13
 
9
14
 
10
15
  var _chunkOS76JPG2cjs = require('./chunk-OS76JPG2.cjs');
@@ -601,7 +606,7 @@ var CAC = class extends _events.EventEmitter {
601
606
  };
602
607
  var cac = (name = "") => new CAC(name);
603
608
 
604
- // ../../node_modules/.pnpm/package-manager-detector@1.4.0/node_modules/package-manager-detector/dist/commands.mjs
609
+ // ../../node_modules/.pnpm/package-manager-detector@1.4.1/node_modules/package-manager-detector/dist/commands.mjs
605
610
  _chunkOS76JPG2cjs.init_cjs_shims.call(void 0, );
606
611
  function dashDashArg(agent, agentCommand) {
607
612
  return (args) => {
@@ -678,7 +683,7 @@ var bun = {
678
683
  "global": ["bun", "add", "-g", 0],
679
684
  "add": ["bun", "add", 0],
680
685
  "upgrade": ["bun", "update", 0],
681
- "upgrade-interactive": ["bun", "update", 0],
686
+ "upgrade-interactive": ["bun", "update", "-i", 0],
682
687
  "execute": ["bun", "x", 0],
683
688
  "execute-local": ["bun", "x", 0],
684
689
  "uninstall": ["bun", "remove", 0],
@@ -806,7 +811,7 @@ async function generate(options) {
806
811
  for (const { code, fileName: fileName2 } of files) {
807
812
  if (code !== void 0) {
808
813
  await _fsextra2.default.outputFile(_pathe2.default.resolve(basepath, fileName2), code, "utf8");
809
- _chunkN2SUN4MXcjs.logger_default.success(`${composePath(outDir, fileName2)} \u521B\u5EFA\u6210\u529F\uFF01`);
814
+ _chunkXEHEGODScjs.logger_default.success(`${composePath(outDir, fileName2)} \u521B\u5EFA\u6210\u529F\uFF01`);
810
815
  }
811
816
  }
812
817
  }
@@ -844,7 +849,7 @@ async function readTemplateFile(templatePath, context) {
844
849
  // src/cli.ts
845
850
  var cli = cac("weapp-vite");
846
851
  try {
847
- _chunkN2SUN4MXcjs.checkRuntime.call(void 0, {
852
+ _chunkXEHEGODScjs.checkRuntime.call(void 0, {
848
853
  bun: "0.0.0",
849
854
  deno: "0.0.0",
850
855
  node: "20.19.0"
@@ -862,7 +867,7 @@ async function loadConfig(configFile) {
862
867
  mode: "development"
863
868
  };
864
869
  const loaded = await _vite.loadConfigFromFile.call(void 0, configEnv, resolvedConfigFile, cwd);
865
- const weappConfigFilePath = await _chunkN2SUN4MXcjs.resolveWeappConfigFile.call(void 0, {
870
+ const weappConfigFilePath = await _chunkXEHEGODScjs.resolveWeappConfigFile.call(void 0, {
866
871
  root: cwd,
867
872
  specified: resolvedConfigFile
868
873
  });
@@ -900,22 +905,54 @@ async function loadConfig(configFile) {
900
905
  };
901
906
  }
902
907
  var logBuildAppFinishOnlyShowOnce = false;
903
- function logBuildAppFinish(configService) {
904
- if (!logBuildAppFinishOnlyShowOnce) {
905
- const { command, args } = _nullishCoalesce(resolveCommand(
906
- configService.packageManager.agent,
907
- "run",
908
- ["open"]
909
- ), () => ( {
910
- command: "npm",
911
- args: ["run", "open"]
912
- }));
913
- const devCommand = `${command} ${args.join(" ")}`;
914
- _chunkN2SUN4MXcjs.logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
915
- _chunkN2SUN4MXcjs.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`);
916
- _chunkN2SUN4MXcjs.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");
908
+ function logBuildAppFinish(configService, webServer, options = {}) {
909
+ if (logBuildAppFinishOnlyShowOnce) {
910
+ return;
911
+ }
912
+ const { skipMini = false, skipWeb = false } = options;
913
+ if (skipMini) {
914
+ if (webServer) {
915
+ const urls = webServer.resolvedUrls;
916
+ const candidates = urls ? [..._nullishCoalesce(urls.local, () => ( [])), ..._nullishCoalesce(urls.network, () => ( []))] : [];
917
+ if (candidates.length > 0) {
918
+ _chunkXEHEGODScjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
919
+ for (const url of candidates) {
920
+ _chunkXEHEGODScjs.logger_default.info(` \u279C ${url}`);
921
+ }
922
+ } else {
923
+ _chunkXEHEGODScjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
924
+ }
925
+ } else {
926
+ _chunkXEHEGODScjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
927
+ }
917
928
  logBuildAppFinishOnlyShowOnce = true;
929
+ return;
930
+ }
931
+ const { command, args } = _nullishCoalesce(resolveCommand(
932
+ configService.packageManager.agent,
933
+ "run",
934
+ ["open"]
935
+ ), () => ( {
936
+ command: "npm",
937
+ args: ["run", "open"]
938
+ }));
939
+ const devCommand = `${command} ${args.join(" ")}`;
940
+ _chunkXEHEGODScjs.logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
941
+ _chunkXEHEGODScjs.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`);
942
+ _chunkXEHEGODScjs.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");
943
+ if (!skipWeb && webServer) {
944
+ const urls = webServer.resolvedUrls;
945
+ const candidates = urls ? [..._nullishCoalesce(urls.local, () => ( [])), ..._nullishCoalesce(urls.network, () => ( []))] : [];
946
+ if (candidates.length > 0) {
947
+ _chunkXEHEGODScjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
948
+ for (const url of candidates) {
949
+ _chunkXEHEGODScjs.logger_default.info(` \u279C ${url}`);
950
+ }
951
+ } else {
952
+ _chunkXEHEGODScjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
953
+ }
918
954
  }
955
+ logBuildAppFinishOnlyShowOnce = true;
919
956
  }
920
957
  function filterDuplicateOptions(options) {
921
958
  for (const [key, value] of Object.entries(options)) {
@@ -942,28 +979,104 @@ async function openIde() {
942
979
  try {
943
980
  await _weappidecli.parse.call(void 0, ["open", "-p"]);
944
981
  } catch (error) {
945
- _chunkN2SUN4MXcjs.logger_default.error(error);
982
+ _chunkXEHEGODScjs.logger_default.error(error);
983
+ }
984
+ }
985
+ function logRuntimeTarget(targets) {
986
+ _chunkXEHEGODScjs.logger_default.info(`\u76EE\u6807\u5E73\u53F0\uFF1A${targets.label}`);
987
+ }
988
+ function resolveRuntimeTargets(options) {
989
+ const rawPlatform = typeof options.platform === "string" ? options.platform : typeof options.p === "string" ? options.p : void 0;
990
+ if (!rawPlatform) {
991
+ return {
992
+ runMini: true,
993
+ runWeb: false,
994
+ mpPlatform: _chunkXEHEGODScjs.DEFAULT_MP_PLATFORM,
995
+ label: _chunkXEHEGODScjs.DEFAULT_MP_PLATFORM
996
+ };
997
+ }
998
+ const normalized = _chunkXEHEGODScjs.normalizeMiniPlatform.call(void 0, rawPlatform);
999
+ if (!normalized) {
1000
+ return {
1001
+ runMini: true,
1002
+ runWeb: false,
1003
+ mpPlatform: _chunkXEHEGODScjs.DEFAULT_MP_PLATFORM,
1004
+ label: _chunkXEHEGODScjs.DEFAULT_MP_PLATFORM
1005
+ };
1006
+ }
1007
+ if (normalized === "h5" || normalized === "web") {
1008
+ return {
1009
+ runMini: false,
1010
+ runWeb: true,
1011
+ mpPlatform: void 0,
1012
+ label: normalized === "h5" ? "h5" : "web"
1013
+ };
1014
+ }
1015
+ const mpPlatform = _chunkXEHEGODScjs.resolveMiniPlatform.call(void 0, normalized);
1016
+ if (mpPlatform) {
1017
+ return {
1018
+ runMini: true,
1019
+ runWeb: false,
1020
+ mpPlatform,
1021
+ label: mpPlatform
1022
+ };
1023
+ }
1024
+ _chunkXEHEGODScjs.logger_default.warn(`\u672A\u8BC6\u522B\u7684\u5E73\u53F0 "${rawPlatform}"\uFF0C\u5DF2\u56DE\u9000\u5230 ${_chunkXEHEGODScjs.DEFAULT_MP_PLATFORM}`);
1025
+ return {
1026
+ runMini: true,
1027
+ runWeb: false,
1028
+ mpPlatform: _chunkXEHEGODScjs.DEFAULT_MP_PLATFORM,
1029
+ label: _chunkXEHEGODScjs.DEFAULT_MP_PLATFORM
1030
+ };
1031
+ }
1032
+ function createInlineConfig(mpPlatform) {
1033
+ if (!mpPlatform) {
1034
+ return void 0;
946
1035
  }
1036
+ return {
1037
+ weapp: {
1038
+ platform: mpPlatform
1039
+ }
1040
+ };
947
1041
  }
948
1042
  cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {
949
1043
  type: [convertBase]
950
1044
  }).option("-l, --logLevel <level>", `[string] info | warn | error | silent`).option("--clearScreen", `[boolean] allow/disable clear screen when logging`).option("-d, --debug [feat]", `[string | boolean] show debug logs`).option("-f, --filter <filter>", `[string] filter debug logs`).option("-m, --mode <mode>", `[string] set env mode`);
951
- cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).action(async (root, options) => {
1045
+ cli.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) => {
952
1046
  filterDuplicateOptions(options);
953
1047
  const configFile = resolveConfigFile(options);
954
- const { buildService, configService } = await _chunkN2SUN4MXcjs.createCompilerContext.call(void 0, {
1048
+ const targets = resolveRuntimeTargets(options);
1049
+ logRuntimeTarget(targets);
1050
+ const inlineConfig = createInlineConfig(targets.mpPlatform);
1051
+ const { buildService, configService, webService } = await _chunkLX2OMRQ4cjs.createCompilerContext.call(void 0, {
955
1052
  cwd: root,
956
1053
  mode: _nullishCoalesce(options.mode, () => ( "development")),
957
1054
  isDev: true,
958
- configFile
1055
+ configFile,
1056
+ inlineConfig
959
1057
  });
960
- await buildService.build(options);
961
- logBuildAppFinish(configService);
962
- if (options.open) {
1058
+ if (targets.runMini) {
1059
+ await buildService.build(options);
1060
+ }
1061
+ let webServer;
1062
+ if (targets.runWeb) {
1063
+ try {
1064
+ webServer = await _optionalChain([webService, 'optionalAccess', _15 => _15.startDevServer, 'call', _16 => _16()]);
1065
+ } catch (error) {
1066
+ _chunkXEHEGODScjs.logger_default.error(error);
1067
+ throw error;
1068
+ }
1069
+ }
1070
+ if (targets.runMini) {
1071
+ logBuildAppFinish(configService, webServer, { skipWeb: !targets.runWeb });
1072
+ } else if (targets.runWeb) {
1073
+ logBuildAppFinish(configService, webServer, { skipMini: true });
1074
+ }
1075
+ if (options.open && targets.runMini) {
963
1076
  await openIde();
964
1077
  }
965
1078
  });
966
- cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option(
1079
+ cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).option(
967
1080
  "--sourcemap [output]",
968
1081
  `[boolean | "inline" | "hidden"] output source maps for build (default: false)`
969
1082
  ).option(
@@ -975,14 +1088,32 @@ cli.command("build [root]", "build for production").option("--target <target>",
975
1088
  ).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) => {
976
1089
  filterDuplicateOptions(options);
977
1090
  const configFile = resolveConfigFile(options);
978
- const { buildService, configService } = await _chunkN2SUN4MXcjs.createCompilerContext.call(void 0, {
1091
+ const targets = resolveRuntimeTargets(options);
1092
+ logRuntimeTarget(targets);
1093
+ const inlineConfig = createInlineConfig(targets.mpPlatform);
1094
+ const { buildService, configService, webService } = await _chunkLX2OMRQ4cjs.createCompilerContext.call(void 0, {
979
1095
  cwd: root,
980
1096
  mode: _nullishCoalesce(options.mode, () => ( "production")),
981
- configFile
1097
+ configFile,
1098
+ inlineConfig
982
1099
  });
983
- await buildService.build(options);
984
- logBuildAppFinish(configService);
985
- if (options.open) {
1100
+ if (targets.runMini) {
1101
+ await buildService.build(options);
1102
+ }
1103
+ const webConfig = configService.weappWebConfig;
1104
+ if (targets.runWeb && _optionalChain([webConfig, 'optionalAccess', _17 => _17.enabled])) {
1105
+ try {
1106
+ await _optionalChain([webService, 'optionalAccess', _18 => _18.build, 'call', _19 => _19()]);
1107
+ _chunkXEHEGODScjs.logger_default.success(`Web \u6784\u5EFA\u5B8C\u6210\uFF0C\u8F93\u51FA\u76EE\u5F55\uFF1A${configService.relativeCwd(webConfig.outDir)}`);
1108
+ } catch (error) {
1109
+ _chunkXEHEGODScjs.logger_default.error(error);
1110
+ throw error;
1111
+ }
1112
+ }
1113
+ if (targets.runMini) {
1114
+ logBuildAppFinish(configService, void 0, { skipWeb: !targets.runWeb });
1115
+ }
1116
+ if (options.open && targets.runMini) {
986
1117
  await openIde();
987
1118
  }
988
1119
  });
@@ -992,7 +1123,7 @@ cli.command("init").action(async () => {
992
1123
  command: "weapp-vite"
993
1124
  });
994
1125
  } catch (error) {
995
- _chunkN2SUN4MXcjs.logger_default.error(error);
1126
+ _chunkXEHEGODScjs.logger_default.error(error);
996
1127
  }
997
1128
  });
998
1129
  cli.command("open").action(async () => {
@@ -1002,7 +1133,7 @@ cli.command("npm").alias("build:npm").alias("build-npm").action(async () => {
1002
1133
  try {
1003
1134
  await _weappidecli.parse.call(void 0, ["build-npm", "-p"]);
1004
1135
  } catch (error) {
1005
- _chunkN2SUN4MXcjs.logger_default.error(error);
1136
+ _chunkXEHEGODScjs.logger_default.error(error);
1006
1137
  }
1007
1138
  });
1008
1139
  cli.command("g [filepath]", "generate component").alias("generate").option("-a, --app", "type app").option("-p, --page", "type app").option("-n, --name <name>", "filename").action(async (filepath, options) => {
@@ -1017,25 +1148,25 @@ cli.command("g [filepath]", "generate component").alias("generate").option("-a,
1017
1148
  fileName = "app";
1018
1149
  }
1019
1150
  if (filepath === void 0) {
1020
- _chunkN2SUN4MXcjs.logger_default.error("weapp-vite generate <outDir> \u547D\u4EE4\u5FC5\u987B\u4F20\u5165\u8DEF\u5F84\u53C2\u6570 outDir");
1151
+ _chunkXEHEGODScjs.logger_default.error("weapp-vite generate <outDir> \u547D\u4EE4\u5FC5\u987B\u4F20\u5165\u8DEF\u5F84\u53C2\u6570 outDir");
1021
1152
  return;
1022
1153
  }
1023
1154
  if (options.page) {
1024
1155
  type = "page";
1025
1156
  }
1026
- const generateOptions = _optionalChain([config, 'optionalAccess', _15 => _15.config, 'access', _16 => _16.weapp, 'optionalAccess', _17 => _17.generate]);
1027
- fileName = _nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _18 => _18.filenames, 'optionalAccess', _19 => _19[type]]), () => ( fileName));
1157
+ const generateOptions = _optionalChain([config, 'optionalAccess', _20 => _20.config, 'access', _21 => _21.weapp, 'optionalAccess', _22 => _22.generate]);
1158
+ fileName = _nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _23 => _23.filenames, 'optionalAccess', _24 => _24[type]]), () => ( fileName));
1028
1159
  await generate({
1029
- outDir: _pathe2.default.join(_nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _20 => _20.dirs, 'optionalAccess', _21 => _21[type]]), () => ( "")), filepath),
1160
+ outDir: _pathe2.default.join(_nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _25 => _25.dirs, 'optionalAccess', _26 => _26[type]]), () => ( "")), filepath),
1030
1161
  type,
1031
1162
  fileName,
1032
- extensions: _optionalChain([generateOptions, 'optionalAccess', _22 => _22.extensions]),
1033
- templates: _optionalChain([generateOptions, 'optionalAccess', _23 => _23.templates])
1163
+ extensions: _optionalChain([generateOptions, 'optionalAccess', _27 => _27.extensions]),
1164
+ templates: _optionalChain([generateOptions, 'optionalAccess', _28 => _28.templates])
1034
1165
  });
1035
1166
  });
1036
1167
  cli.command("create [outDir]", "create project").option("-t, --template <type>", "template type").action(async (outDir, options) => {
1037
1168
  await _init.createProject.call(void 0, outDir, options.template);
1038
1169
  });
1039
1170
  cli.help();
1040
- cli.version(_chunkN2SUN4MXcjs.VERSION);
1171
+ cli.version(_chunkXEHEGODScjs.VERSION);
1041
1172
  cli.parse();
package/dist/cli.mjs CHANGED
@@ -1,10 +1,15 @@
1
1
  import {
2
+ createCompilerContext
3
+ } from "./chunk-KW3QAG67.mjs";
4
+ import {
5
+ DEFAULT_MP_PLATFORM,
2
6
  VERSION,
3
7
  checkRuntime,
4
- createCompilerContext,
5
8
  logger_default,
9
+ normalizeMiniPlatform,
10
+ resolveMiniPlatform,
6
11
  resolveWeappConfigFile
7
- } from "./chunk-JGSE2EOU.mjs";
12
+ } from "./chunk-UT7K35VH.mjs";
8
13
  import {
9
14
  init_esm_shims
10
15
  } from "./chunk-7MAZ2JUY.mjs";
@@ -601,7 +606,7 @@ var CAC = class extends EventEmitter {
601
606
  };
602
607
  var cac = (name = "") => new CAC(name);
603
608
 
604
- // ../../node_modules/.pnpm/package-manager-detector@1.4.0/node_modules/package-manager-detector/dist/commands.mjs
609
+ // ../../node_modules/.pnpm/package-manager-detector@1.4.1/node_modules/package-manager-detector/dist/commands.mjs
605
610
  init_esm_shims();
606
611
  function dashDashArg(agent, agentCommand) {
607
612
  return (args) => {
@@ -678,7 +683,7 @@ var bun = {
678
683
  "global": ["bun", "add", "-g", 0],
679
684
  "add": ["bun", "add", 0],
680
685
  "upgrade": ["bun", "update", 0],
681
- "upgrade-interactive": ["bun", "update", 0],
686
+ "upgrade-interactive": ["bun", "update", "-i", 0],
682
687
  "execute": ["bun", "x", 0],
683
688
  "execute-local": ["bun", "x", 0],
684
689
  "uninstall": ["bun", "remove", 0],
@@ -900,22 +905,54 @@ async function loadConfig(configFile) {
900
905
  };
901
906
  }
902
907
  var logBuildAppFinishOnlyShowOnce = false;
903
- function logBuildAppFinish(configService) {
904
- if (!logBuildAppFinishOnlyShowOnce) {
905
- const { command, args } = resolveCommand(
906
- configService.packageManager.agent,
907
- "run",
908
- ["open"]
909
- ) ?? {
910
- command: "npm",
911
- args: ["run", "open"]
912
- };
913
- const devCommand = `${command} ${args.join(" ")}`;
914
- logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
915
- 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`);
916
- 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");
908
+ function logBuildAppFinish(configService, webServer, options = {}) {
909
+ if (logBuildAppFinishOnlyShowOnce) {
910
+ return;
911
+ }
912
+ const { skipMini = false, skipWeb = false } = options;
913
+ if (skipMini) {
914
+ if (webServer) {
915
+ const urls = webServer.resolvedUrls;
916
+ const candidates = urls ? [...urls.local ?? [], ...urls.network ?? []] : [];
917
+ if (candidates.length > 0) {
918
+ logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
919
+ for (const url of candidates) {
920
+ logger_default.info(` \u279C ${url}`);
921
+ }
922
+ } else {
923
+ logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
924
+ }
925
+ } else {
926
+ logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
927
+ }
917
928
  logBuildAppFinishOnlyShowOnce = true;
929
+ return;
930
+ }
931
+ const { command, args } = resolveCommand(
932
+ configService.packageManager.agent,
933
+ "run",
934
+ ["open"]
935
+ ) ?? {
936
+ command: "npm",
937
+ args: ["run", "open"]
938
+ };
939
+ const devCommand = `${command} ${args.join(" ")}`;
940
+ logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
941
+ 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`);
942
+ 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");
943
+ if (!skipWeb && webServer) {
944
+ const urls = webServer.resolvedUrls;
945
+ const candidates = urls ? [...urls.local ?? [], ...urls.network ?? []] : [];
946
+ if (candidates.length > 0) {
947
+ logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
948
+ for (const url of candidates) {
949
+ logger_default.info(` \u279C ${url}`);
950
+ }
951
+ } else {
952
+ logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
953
+ }
918
954
  }
955
+ logBuildAppFinishOnlyShowOnce = true;
919
956
  }
920
957
  function filterDuplicateOptions(options) {
921
958
  for (const [key, value] of Object.entries(options)) {
@@ -945,25 +982,101 @@ async function openIde() {
945
982
  logger_default.error(error);
946
983
  }
947
984
  }
985
+ function logRuntimeTarget(targets) {
986
+ logger_default.info(`\u76EE\u6807\u5E73\u53F0\uFF1A${targets.label}`);
987
+ }
988
+ function resolveRuntimeTargets(options) {
989
+ const rawPlatform = typeof options.platform === "string" ? options.platform : typeof options.p === "string" ? options.p : void 0;
990
+ if (!rawPlatform) {
991
+ return {
992
+ runMini: true,
993
+ runWeb: false,
994
+ mpPlatform: DEFAULT_MP_PLATFORM,
995
+ label: DEFAULT_MP_PLATFORM
996
+ };
997
+ }
998
+ const normalized = normalizeMiniPlatform(rawPlatform);
999
+ if (!normalized) {
1000
+ return {
1001
+ runMini: true,
1002
+ runWeb: false,
1003
+ mpPlatform: DEFAULT_MP_PLATFORM,
1004
+ label: DEFAULT_MP_PLATFORM
1005
+ };
1006
+ }
1007
+ if (normalized === "h5" || normalized === "web") {
1008
+ return {
1009
+ runMini: false,
1010
+ runWeb: true,
1011
+ mpPlatform: void 0,
1012
+ label: normalized === "h5" ? "h5" : "web"
1013
+ };
1014
+ }
1015
+ const mpPlatform = resolveMiniPlatform(normalized);
1016
+ if (mpPlatform) {
1017
+ return {
1018
+ runMini: true,
1019
+ runWeb: false,
1020
+ mpPlatform,
1021
+ label: mpPlatform
1022
+ };
1023
+ }
1024
+ logger_default.warn(`\u672A\u8BC6\u522B\u7684\u5E73\u53F0 "${rawPlatform}"\uFF0C\u5DF2\u56DE\u9000\u5230 ${DEFAULT_MP_PLATFORM}`);
1025
+ return {
1026
+ runMini: true,
1027
+ runWeb: false,
1028
+ mpPlatform: DEFAULT_MP_PLATFORM,
1029
+ label: DEFAULT_MP_PLATFORM
1030
+ };
1031
+ }
1032
+ function createInlineConfig(mpPlatform) {
1033
+ if (!mpPlatform) {
1034
+ return void 0;
1035
+ }
1036
+ return {
1037
+ weapp: {
1038
+ platform: mpPlatform
1039
+ }
1040
+ };
1041
+ }
948
1042
  cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {
949
1043
  type: [convertBase]
950
1044
  }).option("-l, --logLevel <level>", `[string] info | warn | error | silent`).option("--clearScreen", `[boolean] allow/disable clear screen when logging`).option("-d, --debug [feat]", `[string | boolean] show debug logs`).option("-f, --filter <filter>", `[string] filter debug logs`).option("-m, --mode <mode>", `[string] set env mode`);
951
- cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).action(async (root, options) => {
1045
+ cli.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) => {
952
1046
  filterDuplicateOptions(options);
953
1047
  const configFile = resolveConfigFile(options);
954
- const { buildService, configService } = await createCompilerContext({
1048
+ const targets = resolveRuntimeTargets(options);
1049
+ logRuntimeTarget(targets);
1050
+ const inlineConfig = createInlineConfig(targets.mpPlatform);
1051
+ const { buildService, configService, webService } = await createCompilerContext({
955
1052
  cwd: root,
956
1053
  mode: options.mode ?? "development",
957
1054
  isDev: true,
958
- configFile
1055
+ configFile,
1056
+ inlineConfig
959
1057
  });
960
- await buildService.build(options);
961
- logBuildAppFinish(configService);
962
- if (options.open) {
1058
+ if (targets.runMini) {
1059
+ await buildService.build(options);
1060
+ }
1061
+ let webServer;
1062
+ if (targets.runWeb) {
1063
+ try {
1064
+ webServer = await webService?.startDevServer();
1065
+ } catch (error) {
1066
+ logger_default.error(error);
1067
+ throw error;
1068
+ }
1069
+ }
1070
+ if (targets.runMini) {
1071
+ logBuildAppFinish(configService, webServer, { skipWeb: !targets.runWeb });
1072
+ } else if (targets.runWeb) {
1073
+ logBuildAppFinish(configService, webServer, { skipMini: true });
1074
+ }
1075
+ if (options.open && targets.runMini) {
963
1076
  await openIde();
964
1077
  }
965
1078
  });
966
- cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option(
1079
+ cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).option(
967
1080
  "--sourcemap [output]",
968
1081
  `[boolean | "inline" | "hidden"] output source maps for build (default: false)`
969
1082
  ).option(
@@ -975,14 +1088,32 @@ cli.command("build [root]", "build for production").option("--target <target>",
975
1088
  ).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) => {
976
1089
  filterDuplicateOptions(options);
977
1090
  const configFile = resolveConfigFile(options);
978
- const { buildService, configService } = await createCompilerContext({
1091
+ const targets = resolveRuntimeTargets(options);
1092
+ logRuntimeTarget(targets);
1093
+ const inlineConfig = createInlineConfig(targets.mpPlatform);
1094
+ const { buildService, configService, webService } = await createCompilerContext({
979
1095
  cwd: root,
980
1096
  mode: options.mode ?? "production",
981
- configFile
1097
+ configFile,
1098
+ inlineConfig
982
1099
  });
983
- await buildService.build(options);
984
- logBuildAppFinish(configService);
985
- if (options.open) {
1100
+ if (targets.runMini) {
1101
+ await buildService.build(options);
1102
+ }
1103
+ const webConfig = configService.weappWebConfig;
1104
+ if (targets.runWeb && webConfig?.enabled) {
1105
+ try {
1106
+ await webService?.build();
1107
+ logger_default.success(`Web \u6784\u5EFA\u5B8C\u6210\uFF0C\u8F93\u51FA\u76EE\u5F55\uFF1A${configService.relativeCwd(webConfig.outDir)}`);
1108
+ } catch (error) {
1109
+ logger_default.error(error);
1110
+ throw error;
1111
+ }
1112
+ }
1113
+ if (targets.runMini) {
1114
+ logBuildAppFinish(configService, void 0, { skipWeb: !targets.runWeb });
1115
+ }
1116
+ if (options.open && targets.runMini) {
986
1117
  await openIde();
987
1118
  }
988
1119
  });