weapp-vite 5.2.3 → 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/client.d.ts +17 -3
- package/dist/auto-import-components/resolvers.cjs +6 -2
- package/dist/auto-import-components/resolvers.d.cts +2 -2
- package/dist/auto-import-components/resolvers.d.ts +2 -2
- package/dist/auto-import-components/resolvers.mjs +6 -2
- package/dist/auto-routes.cjs +51 -0
- package/dist/auto-routes.d.cts +10 -0
- package/dist/auto-routes.d.ts +8 -0
- package/dist/auto-routes.mjs +51 -0
- package/dist/chunk-KW3QAG67.mjs +33 -0
- package/dist/chunk-LX2OMRQ4.cjs +33 -0
- package/dist/{chunk-UTHLNBNC.mjs → chunk-UT7K35VH.mjs} +3012 -814
- package/dist/{chunk-GMCAZZQY.cjs → chunk-XEHEGODS.cjs} +3014 -816
- package/dist/cli.cjs +220 -45
- package/dist/cli.mjs +209 -34
- package/dist/{config-CEyL0Mum.d.cts → config-DNP6NeTc.d.cts} +147 -5
- package/dist/{config-9I2A4BU9.d.ts → config-jhY9Idrt.d.ts} +147 -5
- package/dist/config.d.cts +4 -2
- package/dist/config.d.ts +4 -2
- package/dist/index.cjs +3 -2
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.mjs +2 -1
- package/dist/json.d.cts +5 -3
- package/dist/json.d.ts +5 -3
- package/dist/routes-C9hKJjXs.d.cts +11 -0
- package/dist/routes-C9hKJjXs.d.ts +11 -0
- package/dist/{types-D7SAXpSN.d.cts → types-g_G_na7r.d.cts} +8 -2
- package/dist/{types-D7SAXpSN.d.ts → types-g_G_na7r.d.ts} +8 -2
- package/dist/types.cjs +3 -0
- package/dist/types.d.cts +4 -10
- package/dist/types.d.ts +4 -10
- package/dist/types.mjs +3 -0
- package/package.json +19 -13
package/dist/cli.mjs
CHANGED
|
@@ -1,9 +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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
logger_default,
|
|
9
|
+
normalizeMiniPlatform,
|
|
10
|
+
resolveMiniPlatform,
|
|
11
|
+
resolveWeappConfigFile
|
|
12
|
+
} from "./chunk-UT7K35VH.mjs";
|
|
7
13
|
import {
|
|
8
14
|
init_esm_shims
|
|
9
15
|
} from "./chunk-7MAZ2JUY.mjs";
|
|
@@ -12,6 +18,7 @@ import {
|
|
|
12
18
|
init_esm_shims();
|
|
13
19
|
import process3 from "process";
|
|
14
20
|
import { createProject, initConfig } from "@weapp-core/init";
|
|
21
|
+
import { defu as defu2 } from "@weapp-core/shared";
|
|
15
22
|
|
|
16
23
|
// ../../node_modules/.pnpm/cac@6.7.14/node_modules/cac/dist/index.mjs
|
|
17
24
|
init_esm_shims();
|
|
@@ -599,7 +606,7 @@ var CAC = class extends EventEmitter {
|
|
|
599
606
|
};
|
|
600
607
|
var cac = (name = "") => new CAC(name);
|
|
601
608
|
|
|
602
|
-
// ../../node_modules/.pnpm/package-manager-detector@1.4.
|
|
609
|
+
// ../../node_modules/.pnpm/package-manager-detector@1.4.1/node_modules/package-manager-detector/dist/commands.mjs
|
|
603
610
|
init_esm_shims();
|
|
604
611
|
function dashDashArg(agent, agentCommand) {
|
|
605
612
|
return (args) => {
|
|
@@ -676,7 +683,7 @@ var bun = {
|
|
|
676
683
|
"global": ["bun", "add", "-g", 0],
|
|
677
684
|
"add": ["bun", "add", 0],
|
|
678
685
|
"upgrade": ["bun", "update", 0],
|
|
679
|
-
"upgrade-interactive": ["bun", "update", 0],
|
|
686
|
+
"upgrade-interactive": ["bun", "update", "-i", 0],
|
|
680
687
|
"execute": ["bun", "x", 0],
|
|
681
688
|
"execute-local": ["bun", "x", 0],
|
|
682
689
|
"uninstall": ["bun", "remove", 0],
|
|
@@ -849,29 +856,103 @@ try {
|
|
|
849
856
|
});
|
|
850
857
|
} catch {
|
|
851
858
|
}
|
|
852
|
-
function loadConfig(configFile) {
|
|
853
|
-
|
|
859
|
+
async function loadConfig(configFile) {
|
|
860
|
+
const cwd = process3.cwd();
|
|
861
|
+
let resolvedConfigFile = configFile;
|
|
862
|
+
if (resolvedConfigFile && !path2.isAbsolute(resolvedConfigFile)) {
|
|
863
|
+
resolvedConfigFile = path2.resolve(cwd, resolvedConfigFile);
|
|
864
|
+
}
|
|
865
|
+
const configEnv = {
|
|
854
866
|
command: "serve",
|
|
855
867
|
mode: "development"
|
|
856
|
-
}
|
|
868
|
+
};
|
|
869
|
+
const loaded = await loadConfigFromFile(configEnv, resolvedConfigFile, cwd);
|
|
870
|
+
const weappConfigFilePath = await resolveWeappConfigFile({
|
|
871
|
+
root: cwd,
|
|
872
|
+
specified: resolvedConfigFile
|
|
873
|
+
});
|
|
874
|
+
let weappLoaded;
|
|
875
|
+
if (weappConfigFilePath) {
|
|
876
|
+
const normalizedWeappPath = path2.resolve(weappConfigFilePath);
|
|
877
|
+
const normalizedLoadedPath = loaded?.path ? path2.resolve(loaded.path) : void 0;
|
|
878
|
+
if (normalizedLoadedPath && normalizedLoadedPath === normalizedWeappPath) {
|
|
879
|
+
weappLoaded = loaded;
|
|
880
|
+
} else {
|
|
881
|
+
weappLoaded = await loadConfigFromFile(configEnv, weappConfigFilePath, cwd);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
if (!loaded && !weappLoaded) {
|
|
885
|
+
return void 0;
|
|
886
|
+
}
|
|
887
|
+
const config = loaded?.config ?? (weappLoaded?.config ?? {});
|
|
888
|
+
if (weappLoaded?.config?.weapp) {
|
|
889
|
+
config.weapp = defu2(
|
|
890
|
+
weappLoaded.config.weapp,
|
|
891
|
+
config.weapp ?? {}
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
const dependencySet = /* @__PURE__ */ new Set();
|
|
895
|
+
for (const dependency of loaded?.dependencies ?? []) {
|
|
896
|
+
dependencySet.add(dependency);
|
|
897
|
+
}
|
|
898
|
+
for (const dependency of weappLoaded?.dependencies ?? []) {
|
|
899
|
+
dependencySet.add(dependency);
|
|
900
|
+
}
|
|
901
|
+
return {
|
|
902
|
+
config,
|
|
903
|
+
path: weappLoaded?.path ?? loaded?.path ?? resolvedConfigFile,
|
|
904
|
+
dependencies: Array.from(dependencySet)
|
|
905
|
+
};
|
|
857
906
|
}
|
|
858
907
|
var logBuildAppFinishOnlyShowOnce = false;
|
|
859
|
-
function logBuildAppFinish(configService) {
|
|
860
|
-
if (
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
)
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
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
|
+
}
|
|
873
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
|
+
}
|
|
874
954
|
}
|
|
955
|
+
logBuildAppFinishOnlyShowOnce = true;
|
|
875
956
|
}
|
|
876
957
|
function filterDuplicateOptions(options) {
|
|
877
958
|
for (const [key, value] of Object.entries(options)) {
|
|
@@ -901,25 +982,101 @@ async function openIde() {
|
|
|
901
982
|
logger_default.error(error);
|
|
902
983
|
}
|
|
903
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
|
+
}
|
|
904
1042
|
cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {
|
|
905
1043
|
type: [convertBase]
|
|
906
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`);
|
|
907
|
-
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) => {
|
|
908
1046
|
filterDuplicateOptions(options);
|
|
909
1047
|
const configFile = resolveConfigFile(options);
|
|
910
|
-
const
|
|
1048
|
+
const targets = resolveRuntimeTargets(options);
|
|
1049
|
+
logRuntimeTarget(targets);
|
|
1050
|
+
const inlineConfig = createInlineConfig(targets.mpPlatform);
|
|
1051
|
+
const { buildService, configService, webService } = await createCompilerContext({
|
|
911
1052
|
cwd: root,
|
|
912
1053
|
mode: options.mode ?? "development",
|
|
913
1054
|
isDev: true,
|
|
914
|
-
configFile
|
|
1055
|
+
configFile,
|
|
1056
|
+
inlineConfig
|
|
915
1057
|
});
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
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) {
|
|
919
1076
|
await openIde();
|
|
920
1077
|
}
|
|
921
1078
|
});
|
|
922
|
-
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(
|
|
923
1080
|
"--sourcemap [output]",
|
|
924
1081
|
`[boolean | "inline" | "hidden"] output source maps for build (default: false)`
|
|
925
1082
|
).option(
|
|
@@ -931,14 +1088,32 @@ cli.command("build [root]", "build for production").option("--target <target>",
|
|
|
931
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) => {
|
|
932
1089
|
filterDuplicateOptions(options);
|
|
933
1090
|
const configFile = resolveConfigFile(options);
|
|
934
|
-
const
|
|
1091
|
+
const targets = resolveRuntimeTargets(options);
|
|
1092
|
+
logRuntimeTarget(targets);
|
|
1093
|
+
const inlineConfig = createInlineConfig(targets.mpPlatform);
|
|
1094
|
+
const { buildService, configService, webService } = await createCompilerContext({
|
|
935
1095
|
cwd: root,
|
|
936
1096
|
mode: options.mode ?? "production",
|
|
937
|
-
configFile
|
|
1097
|
+
configFile,
|
|
1098
|
+
inlineConfig
|
|
938
1099
|
});
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
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) {
|
|
942
1117
|
await openIde();
|
|
943
1118
|
}
|
|
944
1119
|
});
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { InlineConfig, UserConfig as UserConfig$1, UserConfigFnObject, UserConfigExport } from 'vite';
|
|
2
|
-
import { GenerateType, Component, Theme, Sitemap, App, Page, Plugin } from '@weapp-core/schematics';
|
|
3
1
|
import { InputOption, RolldownOutput, RolldownWatcher } from 'rolldown';
|
|
2
|
+
import { InlineConfig, UserConfig as UserConfig$1, ViteDevServer, build, UserConfigFnObject, UserConfigExport } from 'vite';
|
|
3
|
+
import { A as AutoRoutes } from './routes-C9hKJjXs.cjs';
|
|
4
|
+
import { a as Resolver, R as ResolvedValue } from './types-g_G_na7r.cjs';
|
|
4
5
|
import { Options } from 'tsdown';
|
|
6
|
+
import { GenerateType, Component, Theme, Sitemap, App, Page, Plugin } from '@weapp-core/schematics';
|
|
7
|
+
import { WeappWebPluginOptions } from '@weapp-vite/web';
|
|
5
8
|
import { WrapPluginOptions } from 'vite-plugin-performance';
|
|
6
9
|
import { PluginOptions } from 'vite-tsconfig-paths';
|
|
7
|
-
import { R as Resolver, a as ResolvedValue } from './types-D7SAXpSN.cjs';
|
|
8
10
|
import PQueue from 'p-queue';
|
|
9
11
|
import { DetectResult } from 'package-manager-detector';
|
|
10
12
|
import { PackageJson } from 'pkg-types';
|
|
@@ -45,7 +47,7 @@ interface AliasOptions {
|
|
|
45
47
|
[find: string]: string;
|
|
46
48
|
};
|
|
47
49
|
}
|
|
48
|
-
type MpPlatform = 'weapp' | 'alipay' | 'tt';
|
|
50
|
+
type MpPlatform = 'weapp' | 'alipay' | 'tt' | 'swan' | 'jd' | 'xhs';
|
|
49
51
|
interface SubPackage {
|
|
50
52
|
pages: string[];
|
|
51
53
|
root: string;
|
|
@@ -116,6 +118,35 @@ interface CopyOptions {
|
|
|
116
118
|
filter?: (filePath: string, index: number, array: string[]) => boolean;
|
|
117
119
|
}
|
|
118
120
|
type CopyGlobs = string[];
|
|
121
|
+
interface WeappWebConfig {
|
|
122
|
+
/**
|
|
123
|
+
* @description 是否启用浏览器端运行时集成
|
|
124
|
+
* @default false
|
|
125
|
+
*/
|
|
126
|
+
enable?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* @description Web 侧项目根目录(即 index.html 所在目录)
|
|
129
|
+
* @default 项目根目录
|
|
130
|
+
*/
|
|
131
|
+
root?: string;
|
|
132
|
+
/**
|
|
133
|
+
* @description 小程序源码目录(相对于 `root`),默认与 `weapp.srcRoot` 保持一致
|
|
134
|
+
*/
|
|
135
|
+
srcDir?: string;
|
|
136
|
+
/**
|
|
137
|
+
* @description Web 构建产物输出目录;相对路径基于 `root`
|
|
138
|
+
* @default "dist-web"
|
|
139
|
+
*/
|
|
140
|
+
outDir?: string;
|
|
141
|
+
/**
|
|
142
|
+
* @description 传递给 `weappWebPlugin` 的额外参数(不包含 `srcDir`)
|
|
143
|
+
*/
|
|
144
|
+
pluginOptions?: Partial<Omit<WeappWebPluginOptions, 'srcDir'>>;
|
|
145
|
+
/**
|
|
146
|
+
* @description 额外合并到 Web 构建中的 Vite 内联配置
|
|
147
|
+
*/
|
|
148
|
+
vite?: InlineConfig;
|
|
149
|
+
}
|
|
119
150
|
interface AutoImportComponents {
|
|
120
151
|
/**
|
|
121
152
|
* 自动导入组件
|
|
@@ -125,6 +156,27 @@ interface AutoImportComponents {
|
|
|
125
156
|
* 自动导入组件解析器
|
|
126
157
|
*/
|
|
127
158
|
resolvers?: Resolver[];
|
|
159
|
+
/**
|
|
160
|
+
* 自动导入组件清单输出路径,默认输出到 `vite.config.ts` 同级目录的 `auto-import-components.json`
|
|
161
|
+
* - `true` 或未指定: 按默认路径输出
|
|
162
|
+
* - 传入字符串: 指定输出路径 (支持绝对/相对路径)
|
|
163
|
+
* - `false`: 不生成清单文件
|
|
164
|
+
*/
|
|
165
|
+
output?: string | boolean;
|
|
166
|
+
/**
|
|
167
|
+
* 生成 WXML 组件 props 类型声明文件。
|
|
168
|
+
* - `true`: 输出到 `vite.config.ts` 同级目录的 `typed-components.d.ts`
|
|
169
|
+
* - 传入字符串: 自定义输出路径 (支持绝对/相对路径)
|
|
170
|
+
* - `false` 或未配置: 不生成类型文件
|
|
171
|
+
*/
|
|
172
|
+
typedComponents?: boolean | string;
|
|
173
|
+
/**
|
|
174
|
+
* 生成 VS Code HTML customData 用于模板补全。
|
|
175
|
+
* - `true`: 输出到 `vite.config.ts` 同级目录的 `mini-program.html-data.json`
|
|
176
|
+
* - 传入字符串: 自定义输出路径 (支持绝对/相对路径)
|
|
177
|
+
* - `false` 或未配置: 不生成 customData
|
|
178
|
+
*/
|
|
179
|
+
htmlCustomData?: boolean | string;
|
|
128
180
|
}
|
|
129
181
|
type EnhanceWxmlOptions = ScanWxmlOptions & HandleWxmlOptions;
|
|
130
182
|
interface ScanWxmlOptions {
|
|
@@ -153,6 +205,7 @@ interface BuildNpmPackageMeta {
|
|
|
153
205
|
name: string;
|
|
154
206
|
entry: InputOption;
|
|
155
207
|
}
|
|
208
|
+
type JsFormat = 'cjs' | 'esm';
|
|
156
209
|
interface WeappViteConfig {
|
|
157
210
|
/**
|
|
158
211
|
* @description 应用入口目录 (app.json 所在的目录)
|
|
@@ -160,6 +213,12 @@ interface WeappViteConfig {
|
|
|
160
213
|
* @default '.'
|
|
161
214
|
*/
|
|
162
215
|
srcRoot?: string;
|
|
216
|
+
/**
|
|
217
|
+
* @description 是否启用自动路由模块 (`weapp-vite/auto-routes`)
|
|
218
|
+
* 默认关闭,需要显式启用后才会扫描 `pages/` 目录并生成路由清单。
|
|
219
|
+
* @default false
|
|
220
|
+
*/
|
|
221
|
+
autoRoutes?: boolean;
|
|
163
222
|
/**
|
|
164
223
|
* @description 插件入口目录 (plugin.json 所在的目录)
|
|
165
224
|
* @default undefined
|
|
@@ -214,6 +273,11 @@ interface WeappViteConfig {
|
|
|
214
273
|
* 默认情况下包括大部分的图片资源格式
|
|
215
274
|
*/
|
|
216
275
|
copy?: CopyOptions;
|
|
276
|
+
/**
|
|
277
|
+
* @group Web 运行时
|
|
278
|
+
* 浏览器端运行时相关配置
|
|
279
|
+
*/
|
|
280
|
+
web?: WeappWebConfig;
|
|
217
281
|
/**
|
|
218
282
|
* @description 额外的 wxml 文件
|
|
219
283
|
* 把这个方法,扫描到的 `wxml` 添加到额外的 `wxml` 文件列表, **处理** 之后输出到最终的产物中
|
|
@@ -227,6 +291,28 @@ interface WeappViteConfig {
|
|
|
227
291
|
*/
|
|
228
292
|
platform?: MpPlatform;
|
|
229
293
|
/**
|
|
294
|
+
* @description 生成的 JS 模块格式
|
|
295
|
+
* - `cjs`: 输出 CommonJS
|
|
296
|
+
* - `esm`: 输出 ESM,需要在微信开发者工具中启用「ES6 转 ES5」
|
|
297
|
+
* @default 'cjs'
|
|
298
|
+
*/
|
|
299
|
+
jsFormat?: JsFormat;
|
|
300
|
+
/**
|
|
301
|
+
* @description 是否启用基于 `@swc/core` 的 ES5 降级(仅支持 `jsFormat: 'cjs'`)
|
|
302
|
+
* @default false
|
|
303
|
+
*/
|
|
304
|
+
es5?: boolean;
|
|
305
|
+
wxml?: EnhanceOptions['wxml'];
|
|
306
|
+
/**
|
|
307
|
+
* wxs 增强
|
|
308
|
+
*/
|
|
309
|
+
wxs?: EnhanceOptions['wxs'];
|
|
310
|
+
/**
|
|
311
|
+
* 自动导入小程序组件
|
|
312
|
+
*/
|
|
313
|
+
autoImportComponents?: AutoImportComponents;
|
|
314
|
+
/**
|
|
315
|
+
* @deprecated 请改用顶层的 `wxml`、`wxs` 与 `autoImportComponents`
|
|
230
316
|
* 增强配置
|
|
231
317
|
*/
|
|
232
318
|
enhance?: EnhanceOptions;
|
|
@@ -355,7 +441,9 @@ interface LoadConfigResult {
|
|
|
355
441
|
packageJsonPath: string;
|
|
356
442
|
platform: MpPlatform;
|
|
357
443
|
srcRoot: string;
|
|
444
|
+
configFilePath?: string;
|
|
358
445
|
currentSubPackageRoot?: string;
|
|
446
|
+
weappWeb?: ResolvedWeappWebConfig;
|
|
359
447
|
}
|
|
360
448
|
interface PackageInfo {
|
|
361
449
|
name: string;
|
|
@@ -374,6 +462,7 @@ interface ConfigService {
|
|
|
374
462
|
load: (options?: Partial<LoadConfigOptions>) => Promise<LoadConfigResult>;
|
|
375
463
|
mergeWorkers: (...configs: Partial<InlineConfig>[]) => InlineConfig;
|
|
376
464
|
merge: (subPackageMeta?: SubPackageMetaValue, ...configs: Partial<InlineConfig | undefined>[]) => InlineConfig;
|
|
465
|
+
mergeWeb: (...configs: Partial<InlineConfig | undefined>[]) => InlineConfig | undefined;
|
|
377
466
|
readonly defineImportMetaEnv: Record<string, any>;
|
|
378
467
|
readonly cwd: string;
|
|
379
468
|
readonly isDev: boolean;
|
|
@@ -390,11 +479,24 @@ interface ConfigService {
|
|
|
390
479
|
readonly mode: string;
|
|
391
480
|
readonly aliasEntries: ResolvedAlias[];
|
|
392
481
|
readonly platform: MpPlatform;
|
|
482
|
+
readonly configFilePath?: string;
|
|
483
|
+
readonly weappWebConfig?: ResolvedWeappWebConfig;
|
|
393
484
|
relativeCwd: (p: string) => string;
|
|
394
485
|
relativeSrcRoot: (p: string) => string;
|
|
395
486
|
relativeAbsoluteSrcRoot: (p: string) => string;
|
|
396
487
|
readonly currentSubPackageRoot?: string;
|
|
397
488
|
}
|
|
489
|
+
interface ResolvedWeappWebConfig {
|
|
490
|
+
enabled: boolean;
|
|
491
|
+
root: string;
|
|
492
|
+
srcDir: string;
|
|
493
|
+
outDir: string;
|
|
494
|
+
pluginOptions: Omit<WeappWebPluginOptions, 'srcDir'> & {
|
|
495
|
+
srcDir: string;
|
|
496
|
+
};
|
|
497
|
+
userConfig?: InlineConfig;
|
|
498
|
+
source?: WeappWebConfig;
|
|
499
|
+
}
|
|
398
500
|
|
|
399
501
|
type HashInput = string | Buffer;
|
|
400
502
|
declare class FileCache<T extends object> {
|
|
@@ -486,6 +588,16 @@ interface SidecarWatcher {
|
|
|
486
588
|
}
|
|
487
589
|
|
|
488
590
|
interface RuntimeState {
|
|
591
|
+
autoRoutes: {
|
|
592
|
+
routes: AutoRoutes;
|
|
593
|
+
serialized: string;
|
|
594
|
+
moduleCode: string;
|
|
595
|
+
typedDefinition: string;
|
|
596
|
+
watchFiles: Set<string>;
|
|
597
|
+
watchDirs: Set<string>;
|
|
598
|
+
dirty: boolean;
|
|
599
|
+
initialized: boolean;
|
|
600
|
+
};
|
|
489
601
|
autoImport: {
|
|
490
602
|
registry: Map<string, LocalAutoImportMatch>;
|
|
491
603
|
matcher?: (input: string) => boolean;
|
|
@@ -548,6 +660,14 @@ interface WatcherService {
|
|
|
548
660
|
closeAll: () => void;
|
|
549
661
|
}
|
|
550
662
|
|
|
663
|
+
interface WebService {
|
|
664
|
+
readonly devServer?: ViteDevServer;
|
|
665
|
+
isEnabled: () => boolean;
|
|
666
|
+
startDevServer: () => Promise<ViteDevServer | undefined>;
|
|
667
|
+
build: () => Promise<Awaited<ReturnType<typeof build>> | undefined>;
|
|
668
|
+
close: () => Promise<void>;
|
|
669
|
+
}
|
|
670
|
+
|
|
551
671
|
interface WxmlService {
|
|
552
672
|
depsMap: Map<string, Set<string>>;
|
|
553
673
|
tokenMap: Map<string, ScanWxmlResult>;
|
|
@@ -572,6 +692,21 @@ interface AutoImportService {
|
|
|
572
692
|
resolve: (componentName: string, importerBaseName?: string) => AutoImportMatch | undefined;
|
|
573
693
|
filter: (id: string, meta?: SubPackageMetaValue) => boolean;
|
|
574
694
|
getRegisteredLocalComponents: () => LocalAutoImportMatch[];
|
|
695
|
+
awaitManifestWrites: () => Promise<void>;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
interface AutoRoutesService {
|
|
699
|
+
ensureFresh: () => Promise<void>;
|
|
700
|
+
markDirty: () => void;
|
|
701
|
+
getSnapshot: () => AutoRoutes;
|
|
702
|
+
getReference: () => AutoRoutes;
|
|
703
|
+
getModuleCode: () => string;
|
|
704
|
+
getWatchFiles: () => Iterable<string>;
|
|
705
|
+
getWatchDirectories: () => Iterable<string>;
|
|
706
|
+
isRouteFile: (filePath: string) => boolean;
|
|
707
|
+
handleFileChange: (filePath: string, event?: ChangeEvent) => Promise<void>;
|
|
708
|
+
isInitialized: () => boolean;
|
|
709
|
+
isEnabled: () => boolean;
|
|
575
710
|
}
|
|
576
711
|
|
|
577
712
|
interface CompilerContext {
|
|
@@ -581,11 +716,18 @@ interface CompilerContext {
|
|
|
581
716
|
wxmlService: WxmlService;
|
|
582
717
|
jsonService: JsonService;
|
|
583
718
|
watcherService: WatcherService;
|
|
719
|
+
webService: WebService;
|
|
584
720
|
autoImportService: AutoImportService;
|
|
721
|
+
autoRoutesService: AutoRoutesService;
|
|
585
722
|
buildService: BuildService;
|
|
586
723
|
scanService: ScanService;
|
|
587
724
|
}
|
|
588
725
|
|
|
726
|
+
interface WeappVitePluginApi {
|
|
727
|
+
ctx: CompilerContext;
|
|
728
|
+
}
|
|
729
|
+
type ChangeEvent = 'create' | 'update' | 'delete';
|
|
730
|
+
|
|
589
731
|
type ReturnSelf<T> = (config: T) => T;
|
|
590
732
|
type ConfigFn<T> = T | ((ctx: CompilerContext) => T);
|
|
591
733
|
type DefineJsonFn<T> = ReturnSelf<ConfigFn<T>>;
|
|
@@ -605,4 +747,4 @@ declare function defineConfig(config: Promise<UserConfig$1>): Promise<UserConfig
|
|
|
605
747
|
declare function defineConfig(config: UserConfigFnObject): UserConfigFnObject;
|
|
606
748
|
declare function defineConfig(config: UserConfigExport): UserConfigExport;
|
|
607
749
|
|
|
608
|
-
export { type Alias as A, type BuildNpmPackageMeta as B, type CompilerContext as C, type
|
|
750
|
+
export { type Alias as A, type BuildNpmPackageMeta as B, type CompilerContext as C, type WxmlDep as D, type EnhanceWxmlOptions as E, type ScanComponentItem as F, type GenerateExtensionsOptions as G, type HandleWxmlOptions as H, type ComponentsMap as I, type JsFormat as J, type BaseEntry as K, type LoadConfigOptions as L, type MpPlatform as M, type Entry as N, type AppEntry as O, type ProjectConfig as P, type PageEntry as Q, type ResolvedAlias as R, type SubPackage as S, type ComponentEntry as T, type UserConfig as U, type EntryJsonFragment as V, type WeappViteConfig as W, type WeappVitePluginApi as X, type ChangeEvent as Y, defineAppJson as a, definePageJson as b, defineComponentJson as c, defineConfig as d, defineSitemapJson as e, defineThemeJson as f, type AliasOptions as g, type GenerateDirsOptions as h, type GenerateFilenamesOptions as i, type GenerateFileType as j, type GenerateTemplateContext as k, type GenerateTemplateFileSource as l, type GenerateTemplateInlineSource as m, type GenerateTemplateFactory as n, type GenerateTemplate as o, type GenerateTemplateEntry as p, type GenerateTemplateScope as q, type GenerateTemplatesConfig as r, type GenerateOptions as s, type CopyOptions as t, type CopyGlobs as u, type WeappWebConfig as v, type AutoImportComponents as w, type ScanWxmlOptions as x, type EnhanceOptions as y, type SubPackageMetaValue as z };
|