@open-dy/vibecoding-sdk-taro 0.0.1-beta.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/adapters/interest-card/eslint/eslint-plugin-custom-navigation.mjs +290 -0
- package/dist/adapters/interest-card/eslint/taro.mjs +55 -0
- package/dist/adapters/interest-card/runtime/microapp.d.ts +7 -0
- package/dist/adapters/interest-card/runtime/microapp.js +8 -0
- package/dist/adapters/interest-card/runtime/microapp.js.map +1 -0
- package/dist/adapters/interest-card/types/taro.d.ts +28 -0
- package/dist/build/config-overrides.d.ts +19 -0
- package/dist/build/config-overrides.js +35 -0
- package/dist/build/config-overrides.js.map +1 -0
- package/dist/build/index.d.ts +1 -0
- package/dist/build/index.js +2 -0
- package/dist/build/index.js.map +1 -0
- package/dist/build/plugins/app-config.cjs +43 -0
- package/dist/build/plugins/vite-depend-card.d.ts +29 -0
- package/dist/build/plugins/vite-depend-card.js +250 -0
- package/dist/build/plugins/vite-depend-card.js.map +1 -0
- package/dist/build/plugins/vite-image-asset-import.d.ts +10 -0
- package/dist/build/plugins/vite-image-asset-import.js +150 -0
- package/dist/build/plugins/vite-image-asset-import.js.map +1 -0
- package/dist/build/plugins/vite-inline-json.d.ts +4 -0
- package/dist/build/plugins/vite-inline-json.js +129 -0
- package/dist/build/plugins/vite-inline-json.js.map +1 -0
- package/dist/build/plugins/vite-taro-source-location.d.ts +13 -0
- package/dist/build/plugins/vite-taro-source-location.js +159 -0
- package/dist/build/plugins/vite-taro-source-location.js.map +1 -0
- package/dist/build/taro.d.ts +53 -0
- package/dist/build/taro.js +729 -0
- package/dist/build/taro.js.map +1 -0
- package/dist/components/miniapp-open-card.d.ts +19 -0
- package/dist/components/miniapp-open-card.js +3 -0
- package/dist/components/miniapp-open-card.js.map +1 -0
- package/dist/eslint/eslint-plugin-microapp-pages.mjs +659 -0
- package/dist/eslint/server.mjs +69 -0
- package/dist/eslint/taro.mjs +553 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/runtime/douyin-open-button.d.ts +29 -0
- package/dist/internal/runtime/iframe-auth/identity.d.ts +20 -0
- package/dist/internal/runtime/iframe-auth/identity.js +156 -0
- package/dist/internal/runtime/iframe-auth/identity.js.map +1 -0
- package/dist/internal/runtime/iframe-auth/index.d.ts +2 -0
- package/dist/internal/runtime/iframe-auth/index.js +3 -0
- package/dist/internal/runtime/iframe-auth/index.js.map +1 -0
- package/dist/internal/runtime/iframe-auth/sync.d.ts +2 -0
- package/dist/internal/runtime/iframe-auth/sync.js +23 -0
- package/dist/internal/runtime/iframe-auth/sync.js.map +1 -0
- package/dist/lib/measure.d.ts +21 -0
- package/dist/lib/measure.js +101 -0
- package/dist/lib/measure.js.map +1 -0
- package/dist/lib/platform.d.ts +2 -0
- package/dist/lib/platform.js +11 -0
- package/dist/lib/platform.js.map +1 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.js +6 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/reference/llms.txt +36 -0
- package/dist/reference/sdk-api/build/taro/BuildContext.md +53 -0
- package/dist/reference/sdk-api/build/taro/CreateMicroappTaroConfigOptions.md +62 -0
- package/dist/reference/sdk-api/build/taro/createMicroappTaroConfig.md +66 -0
- package/dist/reference/sdk-api/build/taro/index.md +11 -0
- package/dist/reference/sdk-api/runtime/CreateMicroappClientOptions.md +47 -0
- package/dist/reference/sdk-api/runtime/createMicroappClient.md +378 -0
- package/dist/reference/sdk-api/runtime/index.md +10 -0
- package/dist/reference/sdk-api.json +1534 -0
- package/dist/reference/sdk-api.md +43 -0
- package/dist/runtime/client.d.ts +63 -0
- package/dist/runtime/client.js +194 -0
- package/dist/runtime/client.js.map +1 -0
- package/dist/runtime/closed-domain-request-header.d.ts +4 -0
- package/dist/runtime/closed-domain-request-header.js +8 -0
- package/dist/runtime/closed-domain-request-header.js.map +1 -0
- package/dist/runtime/default-client.d.ts +57 -0
- package/dist/runtime/default-client.js +21 -0
- package/dist/runtime/default-client.js.map +1 -0
- package/dist/runtime/default-iframe-auth.d.ts +8 -0
- package/dist/runtime/default-iframe-auth.js +10 -0
- package/dist/runtime/default-iframe-auth.js.map +1 -0
- package/dist/runtime/douyin-container-request.d.ts +11 -0
- package/dist/runtime/douyin-container-request.js +301 -0
- package/dist/runtime/douyin-container-request.js.map +1 -0
- package/dist/runtime/douyin-login-request.d.ts +32 -0
- package/dist/runtime/douyin-login-request.js +400 -0
- package/dist/runtime/douyin-login-request.js.map +1 -0
- package/dist/runtime/globals.d.ts +342 -0
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.js +4 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/network-url.d.ts +3 -0
- package/dist/runtime/network-url.js +53 -0
- package/dist/runtime/network-url.js.map +1 -0
- package/dist/types/taro.d.ts +1 -0
- package/dist/ui/accordion.d.ts +17 -0
- package/dist/ui/accordion.js +60 -0
- package/dist/ui/accordion.js.map +1 -0
- package/dist/ui/alert-dialog.d.ts +33 -0
- package/dist/ui/alert-dialog.js +96 -0
- package/dist/ui/alert-dialog.js.map +1 -0
- package/dist/ui/alert.d.ts +11 -0
- package/dist/ui/alert.js +49 -0
- package/dist/ui/alert.js.map +1 -0
- package/dist/ui/aspect-ratio.d.ts +5 -0
- package/dist/ui/aspect-ratio.js +10 -0
- package/dist/ui/aspect-ratio.js.map +1 -0
- package/dist/ui/avatar.d.ts +14 -0
- package/dist/ui/avatar.js +50 -0
- package/dist/ui/avatar.js.map +1 -0
- package/dist/ui/badge.d.ts +8 -0
- package/dist/ui/badge.js +27 -0
- package/dist/ui/badge.js.map +1 -0
- package/dist/ui/button-group.d.ts +14 -0
- package/dist/ui/button-group.js +52 -0
- package/dist/ui/button-group.js.map +1 -0
- package/dist/ui/button.d.ts +30 -0
- package/dist/ui/button.js +75 -0
- package/dist/ui/button.js.map +1 -0
- package/dist/ui/calendar.d.ts +29 -0
- package/dist/ui/calendar.js +141 -0
- package/dist/ui/calendar.js.map +1 -0
- package/dist/ui/card.d.ts +12 -0
- package/dist/ui/card.js +38 -0
- package/dist/ui/card.js.map +1 -0
- package/dist/ui/carousel.d.ts +30 -0
- package/dist/ui/carousel.js +60 -0
- package/dist/ui/carousel.js.map +1 -0
- package/dist/ui/checkbox.d.ts +9 -0
- package/dist/ui/checkbox.js +20 -0
- package/dist/ui/checkbox.js.map +1 -0
- package/dist/ui/collapsible.d.ts +18 -0
- package/dist/ui/collapsible.js +53 -0
- package/dist/ui/collapsible.js.map +1 -0
- package/dist/ui/combobox.d.ts +55 -0
- package/dist/ui/combobox.js +165 -0
- package/dist/ui/combobox.js.map +1 -0
- package/dist/ui/dialog.d.ts +26 -0
- package/dist/ui/dialog.js +54 -0
- package/dist/ui/dialog.js.map +1 -0
- package/dist/ui/drawer.d.ts +21 -0
- package/dist/ui/drawer.js +57 -0
- package/dist/ui/drawer.js.map +1 -0
- package/dist/ui/dropdown-menu.d.ts +52 -0
- package/dist/ui/dropdown-menu.js +112 -0
- package/dist/ui/dropdown-menu.js.map +1 -0
- package/dist/ui/empty.d.ts +12 -0
- package/dist/ui/empty.js +35 -0
- package/dist/ui/empty.js.map +1 -0
- package/dist/ui/field.d.ts +26 -0
- package/dist/ui/field.js +117 -0
- package/dist/ui/field.js.map +1 -0
- package/dist/ui/helpers.d.ts +6 -0
- package/dist/ui/helpers.js +23 -0
- package/dist/ui/helpers.js.map +1 -0
- package/dist/ui/index.d.ts +47 -0
- package/dist/ui/index.js +48 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/input-group.d.ts +17 -0
- package/dist/ui/input-group.js +122 -0
- package/dist/ui/input-group.js.map +1 -0
- package/dist/ui/input-otp.d.ts +18 -0
- package/dist/ui/input-otp.js +48 -0
- package/dist/ui/input-otp.js.map +1 -0
- package/dist/ui/input.d.ts +5 -0
- package/dist/ui/input.js +8 -0
- package/dist/ui/input.js.map +1 -0
- package/dist/ui/item.d.ts +22 -0
- package/dist/ui/item.js +83 -0
- package/dist/ui/item.js.map +1 -0
- package/dist/ui/label.d.ts +3 -0
- package/dist/ui/label.js +8 -0
- package/dist/ui/label.js.map +1 -0
- package/dist/ui/menubar.d.ts +65 -0
- package/dist/ui/menubar.js +244 -0
- package/dist/ui/menubar.js.map +1 -0
- package/dist/ui/navigation-menu.d.ts +27 -0
- package/dist/ui/navigation-menu.js +72 -0
- package/dist/ui/navigation-menu.js.map +1 -0
- package/dist/ui/pagination.d.ts +17 -0
- package/dist/ui/pagination.js +28 -0
- package/dist/ui/pagination.js.map +1 -0
- package/dist/ui/popover.d.ts +27 -0
- package/dist/ui/popover.js +139 -0
- package/dist/ui/popover.js.map +1 -0
- package/dist/ui/portal.d.ts +5 -0
- package/dist/ui/portal.js +18 -0
- package/dist/ui/portal.js.map +1 -0
- package/dist/ui/progress.d.ts +45 -0
- package/dist/ui/progress.js +67 -0
- package/dist/ui/progress.js.map +1 -0
- package/dist/ui/radio-group.d.ts +12 -0
- package/dist/ui/radio-group.js +29 -0
- package/dist/ui/radio-group.js.map +1 -0
- package/dist/ui/resizable.d.ts +20 -0
- package/dist/ui/resizable.js +244 -0
- package/dist/ui/resizable.js.map +1 -0
- package/dist/ui/scroll-area.d.ts +8 -0
- package/dist/ui/scroll-area.js +34 -0
- package/dist/ui/scroll-area.js.map +1 -0
- package/dist/ui/select.d.ts +35 -0
- package/dist/ui/select.js +136 -0
- package/dist/ui/select.js.map +1 -0
- package/dist/ui/separator.d.ts +5 -0
- package/dist/ui/separator.js +8 -0
- package/dist/ui/separator.js.map +1 -0
- package/dist/ui/sheet.d.ts +26 -0
- package/dist/ui/sheet.js +67 -0
- package/dist/ui/sheet.js.map +1 -0
- package/dist/ui/skeleton.d.ts +3 -0
- package/dist/ui/skeleton.js +8 -0
- package/dist/ui/skeleton.js.map +1 -0
- package/dist/ui/slider.d.ts +12 -0
- package/dist/ui/slider.js +94 -0
- package/dist/ui/slider.js.map +1 -0
- package/dist/ui/sonner.d.ts +6 -0
- package/dist/ui/sonner.js +13 -0
- package/dist/ui/sonner.js.map +1 -0
- package/dist/ui/spinner.d.ts +3 -0
- package/dist/ui/spinner.js +9 -0
- package/dist/ui/spinner.js.map +1 -0
- package/dist/ui/switch.d.ts +11 -0
- package/dist/ui/switch.js +33 -0
- package/dist/ui/switch.js.map +1 -0
- package/dist/ui/table.d.ts +13 -0
- package/dist/ui/table.js +54 -0
- package/dist/ui/table.js.map +1 -0
- package/dist/ui/tabs.d.ts +23 -0
- package/dist/ui/tabs.js +61 -0
- package/dist/ui/tabs.js.map +1 -0
- package/dist/ui/tailwind.css +2 -0
- package/dist/ui/textarea.d.ts +3 -0
- package/dist/ui/textarea.js +13 -0
- package/dist/ui/textarea.js.map +1 -0
- package/dist/ui/theme.css +234 -0
- package/dist/ui/toggle-group.d.ts +19 -0
- package/dist/ui/toggle-group.js +73 -0
- package/dist/ui/toggle-group.js.map +1 -0
- package/dist/ui/toggle.d.ts +14 -0
- package/dist/ui/toggle.js +41 -0
- package/dist/ui/toggle.js.map +1 -0
- package/package.json +97 -0
|
@@ -0,0 +1,729 @@
|
|
|
1
|
+
import tailwindcss from "@tailwindcss/postcss";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { UnifiedViteWeappTailwindcssPlugin } from 'weapp-tailwindcss/vite';
|
|
6
|
+
import { viteImageAssetImportPlugin } from "./plugins/vite-image-asset-import.js";
|
|
7
|
+
import { viteDependCardPlugin } from "./plugins/vite-depend-card.js";
|
|
8
|
+
import { viteInlineJsonPlugin } from "./plugins/vite-inline-json.js";
|
|
9
|
+
import { viteTaroSourceLocationPlugin } from "./plugins/vite-taro-source-location.js";
|
|
10
|
+
const SDK_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
import { applyConfigOverrides } from './config-overrides.js';
|
|
12
|
+
export { applyConfigOverrides, mergeConfigValue } from './config-overrides.js';
|
|
13
|
+
function shouldRewritePreviewRequest(req) {
|
|
14
|
+
if (req.method !== "GET" && req.method !== "HEAD")
|
|
15
|
+
return false;
|
|
16
|
+
if (req.headers.accept && !req.headers.accept.includes("text/html")) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
function isViteOptimizedDepsRequest(url) {
|
|
22
|
+
if (!url)
|
|
23
|
+
return false;
|
|
24
|
+
const cleanUrl = url.split("?")[0].split("#")[0];
|
|
25
|
+
return (cleanUrl.includes("/node_modules/.vite/deps/") ||
|
|
26
|
+
cleanUrl.includes("/@fs/") && cleanUrl.includes("/node_modules/.vite/deps/"));
|
|
27
|
+
}
|
|
28
|
+
function extractUrlFromEstree(node) {
|
|
29
|
+
if (node.type === "Literal" && typeof node.value === "string")
|
|
30
|
+
return node.value;
|
|
31
|
+
if (node.type === "TemplateLiteral") {
|
|
32
|
+
let result = "";
|
|
33
|
+
for (let i = 0; i < node.quasis.length; i++) {
|
|
34
|
+
result += node.quasis[i].value.cooked ?? node.quasis[i].value.raw;
|
|
35
|
+
if (i < node.expressions.length)
|
|
36
|
+
result += `\${${extractUrlFromEstree(node.expressions[i])}}`;
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
if (node.type === "BinaryExpression" && node.operator === "+")
|
|
41
|
+
return extractUrlFromEstree(node.left) + extractUrlFromEstree(node.right);
|
|
42
|
+
if (node.type === "Identifier")
|
|
43
|
+
return `\${${node.name}}`;
|
|
44
|
+
return "<dynamic>";
|
|
45
|
+
}
|
|
46
|
+
function visitEstree(node, callback) {
|
|
47
|
+
callback(node);
|
|
48
|
+
for (const key of Object.keys(node)) {
|
|
49
|
+
const child = node[key];
|
|
50
|
+
if (child && typeof child === "object" && child.type) {
|
|
51
|
+
visitEstree(child, callback);
|
|
52
|
+
}
|
|
53
|
+
else if (Array.isArray(child)) {
|
|
54
|
+
for (const item of child) {
|
|
55
|
+
if (item && typeof item === "object" && item.type)
|
|
56
|
+
visitEstree(item, callback);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const TARGET_METHODS = new Set(["request", "uploadFile", "downloadFile"]);
|
|
62
|
+
const CLIENT_ROUTES_FILE = "/tmp/routes/client-routes.json";
|
|
63
|
+
function writeRoutes(results) {
|
|
64
|
+
try {
|
|
65
|
+
const outDir = path.dirname(CLIENT_ROUTES_FILE);
|
|
66
|
+
if (!fs.existsSync(outDir))
|
|
67
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
68
|
+
fs.writeFileSync(CLIENT_ROUTES_FILE, JSON.stringify(results, null, 2));
|
|
69
|
+
console.log(`\n[NetworkUrlAnalyzerPlugin] Collected ${results.length} client route(s) -> ${CLIENT_ROUTES_FILE}\n`);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Ignore route dump failures in build-time analysis.
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function collectNetworkCalls(ast, id, srcDir, results) {
|
|
76
|
+
visitEstree(ast, (node) => {
|
|
77
|
+
if (node.type === "CallExpression" &&
|
|
78
|
+
node.callee?.type === "MemberExpression" &&
|
|
79
|
+
node.callee.object?.type === "Identifier" &&
|
|
80
|
+
node.callee.object.name === "Network" &&
|
|
81
|
+
node.callee.property?.type === "Identifier" &&
|
|
82
|
+
TARGET_METHODS.has(node.callee.property.name)) {
|
|
83
|
+
const arg = node.arguments?.[0];
|
|
84
|
+
if (arg?.type === "ObjectExpression") {
|
|
85
|
+
const urlProp = arg.properties?.find((p) => p.type === "Property" &&
|
|
86
|
+
((p.key?.type === "Identifier" && p.key.name === "url") ||
|
|
87
|
+
(p.key?.type === "Literal" && p.key.value === "url")));
|
|
88
|
+
if (urlProp) {
|
|
89
|
+
const urlValue = extractUrlFromEstree(urlProp.value);
|
|
90
|
+
results.push({
|
|
91
|
+
method: node.callee.property.name,
|
|
92
|
+
url: urlValue,
|
|
93
|
+
file: path.relative(path.resolve(srcDir, ".."), id),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function networkUrlAnalyzerPlugin(srcDir) {
|
|
101
|
+
const results = [];
|
|
102
|
+
let isBuild = false;
|
|
103
|
+
return {
|
|
104
|
+
name: "network-url-analyzer",
|
|
105
|
+
buildStart() {
|
|
106
|
+
isBuild = !this.meta.watchMode;
|
|
107
|
+
if (!isBuild)
|
|
108
|
+
return;
|
|
109
|
+
results.length = 0;
|
|
110
|
+
try {
|
|
111
|
+
fs.unlinkSync(CLIENT_ROUTES_FILE);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// Ignore missing route snapshot files.
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
transform(code, id) {
|
|
118
|
+
if (!isBuild)
|
|
119
|
+
return;
|
|
120
|
+
try {
|
|
121
|
+
if (!id.startsWith(srcDir) || id.includes("network.ts"))
|
|
122
|
+
return;
|
|
123
|
+
if (!/\.(ts|tsx|js|jsx)$/.test(id))
|
|
124
|
+
return;
|
|
125
|
+
const ast = this.parse(code);
|
|
126
|
+
collectNetworkCalls(ast, id, srcDir, results);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
// Ignore analyzer failures and avoid blocking builds.
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
closeBundle() {
|
|
133
|
+
if (!isBuild)
|
|
134
|
+
return;
|
|
135
|
+
writeRoutes(results);
|
|
136
|
+
results.length = 0;
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function createAppEntryMatcher(srcDir) {
|
|
141
|
+
const candidateEntries = new Set(["app.ts", "app.tsx", "app.js", "app.jsx"].map((name) => path.normalize(path.join(srcDir, name))));
|
|
142
|
+
return (id) => {
|
|
143
|
+
if (!id.includes("/app.") && !id.includes("\\app.")) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
const cleanId = id.split("?")[0];
|
|
147
|
+
return candidateEntries.has(path.normalize(cleanId));
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function buildInjectedViteErrorReporter(targetOrigins) {
|
|
151
|
+
return `
|
|
152
|
+
/* Injected vite error reporter */
|
|
153
|
+
if (typeof window !== "undefined" &&
|
|
154
|
+
window !== window.parent &&
|
|
155
|
+
import.meta.hot &&
|
|
156
|
+
!window.__AGI_VITE_ERROR_SYNC__) {
|
|
157
|
+
window.__AGI_VITE_ERROR_SYNC__ = true;
|
|
158
|
+
const viteErrorTargets = ${JSON.stringify(targetOrigins)};
|
|
159
|
+
const postToParent = (message) => {
|
|
160
|
+
viteErrorTargets.forEach((targetOrigin) => {
|
|
161
|
+
try {
|
|
162
|
+
window.parent.postMessage(message, targetOrigin);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
const normalizeError = (err) => {
|
|
168
|
+
if (!err) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
message: err.message,
|
|
173
|
+
id: err.id,
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
import.meta.hot.on("vite:error", (payload) => {
|
|
178
|
+
const error = normalizeError(payload && payload.err);
|
|
179
|
+
if (!error) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
window.__LAST_VITE_ERROR__ = error;
|
|
183
|
+
postToParent({ type: "VITE_ERROR", hasError: true, error });
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
import.meta.hot.on("vite:beforeUpdate", () => {
|
|
187
|
+
window.__LAST_VITE_ERROR__ = null;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
`;
|
|
191
|
+
}
|
|
192
|
+
// dev-only 路由自愈:app.config 改动重启重载后,若当前 URL 对应页面已从
|
|
193
|
+
// pages 中移除,重定向到新首页。兼容 hash(本地)与 browser(云端 + basename)模式。
|
|
194
|
+
function buildInjectedRouteHealer() {
|
|
195
|
+
return `
|
|
196
|
+
/* Injected dev route healer */
|
|
197
|
+
if (typeof window !== "undefined" && !window.__AGI_ROUTE_HEALER__) {
|
|
198
|
+
window.__AGI_ROUTE_HEALER__ = true;
|
|
199
|
+
var healRoute = function () {
|
|
200
|
+
try {
|
|
201
|
+
var config = window.__taroAppConfig;
|
|
202
|
+
var pages = config && config.pages;
|
|
203
|
+
if (!pages || !pages.length) return;
|
|
204
|
+
var router = config.router || {};
|
|
205
|
+
var mode = router.mode || "hash";
|
|
206
|
+
var basename = router.basename || "";
|
|
207
|
+
var stripBase = function (p) {
|
|
208
|
+
if (basename && p.indexOf(basename) === 0) p = p.slice(basename.length);
|
|
209
|
+
return p.replace(/^\\//, "");
|
|
210
|
+
};
|
|
211
|
+
var currentPath;
|
|
212
|
+
if (mode === "browser" || mode === "multi") {
|
|
213
|
+
currentPath = stripBase(window.location.pathname).split("?")[0];
|
|
214
|
+
} else {
|
|
215
|
+
var hash = window.location.hash || "";
|
|
216
|
+
currentPath = hash.replace(/^#/, "").split("?")[0].replace(/^\\//, "");
|
|
217
|
+
}
|
|
218
|
+
if (!currentPath) return;
|
|
219
|
+
var exists = pages.some(function (p) {
|
|
220
|
+
return p === currentPath || ("/" + p) === ("/" + currentPath);
|
|
221
|
+
});
|
|
222
|
+
if (exists) return;
|
|
223
|
+
var home = pages[0];
|
|
224
|
+
if (mode === "browser" || mode === "multi") {
|
|
225
|
+
var target = (basename ? basename.replace(/\\/$/, "") : "") + "/" + home;
|
|
226
|
+
window.location.replace(target + window.location.search);
|
|
227
|
+
} else {
|
|
228
|
+
window.location.hash = "#/" + home;
|
|
229
|
+
}
|
|
230
|
+
} catch (e) {}
|
|
231
|
+
};
|
|
232
|
+
if (document.readyState === "complete") {
|
|
233
|
+
setTimeout(healRoute, 0);
|
|
234
|
+
} else {
|
|
235
|
+
window.addEventListener("load", function () { setTimeout(healRoute, 0); });
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
`;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* @desc 创建普通小程序的 Taro/Vite 构建配置。
|
|
242
|
+
* @params {CreateMicroappTaroConfigOptions} options 构建配置选项。
|
|
243
|
+
* @return {UserConfigExport} Taro 配置工厂函数。
|
|
244
|
+
* @example createMicroappTaroConfig({ projectRoot: process.cwd() })
|
|
245
|
+
* @ai-intent 创建普通小程序的 Taro/Vite 构建配置。
|
|
246
|
+
* @ai-when 构建脚本需要加载普通小程序的 SDK 配置时。
|
|
247
|
+
* @ai-avoid 不要在业务页面调用该构建工厂,也不要绕过 SDK 修改代理配置。
|
|
248
|
+
* @ai-example createMicroappTaroConfig({ projectRoot: process.cwd() })
|
|
249
|
+
*/
|
|
250
|
+
export function createMicroappTaroConfig(options) {
|
|
251
|
+
return (async (merge) => {
|
|
252
|
+
const DOUYIN_CLOUD_ENV_ID = process.env.DOUYIN_CLOUD_ENV_ID || "";
|
|
253
|
+
const DOUYIN_CLOUD_DEV_ENV_ID = process.env.DOUYIN_CLOUD_DEV_ENV_ID || "";
|
|
254
|
+
const DOUYIN_CLOUD_SERVICE_ID = process.env.DOUYIN_CLOUD_SERVICE_ID || "";
|
|
255
|
+
const APP_ID = process.env.APP_ID || "";
|
|
256
|
+
const OPEN_CARD_ID = process.env.OPEN_CARD_ID || "";
|
|
257
|
+
const AUDIT_DOUYIN_CLOUD_ENV_ID = process.env.AUDIT_DOUYIN_CLOUD_ENV_ID || "";
|
|
258
|
+
const AUDIT_DOUYIN_CLOUD_SERVICE_ID = process.env.AUDIT_DOUYIN_CLOUD_SERVICE_ID || "";
|
|
259
|
+
if (APP_ID) {
|
|
260
|
+
process.env.TARO_APP_ID = APP_ID;
|
|
261
|
+
}
|
|
262
|
+
const projectRoot = path.resolve(options.projectRoot);
|
|
263
|
+
const srcDir = path.resolve(projectRoot, "src");
|
|
264
|
+
// Keep generated projects using their local icons; SDK-based templates use
|
|
265
|
+
// the scoped package while still accepting legacy `lucide-taro` imports.
|
|
266
|
+
const legacyIconEntry = path.resolve(projectRoot, 'icons/dist/lucide-taro.mjs');
|
|
267
|
+
const isH5 = process.env.TARO_ENV === 'h5';
|
|
268
|
+
const viteErrorTargets = options.viteErrorTargets ?? [];
|
|
269
|
+
const cloudDevProjectDomain = viteErrorTargets[0] ?? '';
|
|
270
|
+
let conversationId = '';
|
|
271
|
+
try {
|
|
272
|
+
const meta = JSON.parse(fs.readFileSync('/opt/gem/ai_coding_app/.meta/ai_coding_app_meta.json', 'utf8'));
|
|
273
|
+
conversationId = meta.conversation_id ?? '';
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
// Local development has no cloud metadata.
|
|
277
|
+
}
|
|
278
|
+
const isCloudEnv = Boolean(conversationId);
|
|
279
|
+
const previewBasePath = isCloudEnv
|
|
280
|
+
? `/api/apps/open_ai_coding_chat_server/aio_fe/${conversationId}/preview`
|
|
281
|
+
: '';
|
|
282
|
+
const aioServerPath = isCloudEnv
|
|
283
|
+
? `${cloudDevProjectDomain}/api/apps/open_ai_coding_chat_server/aio_server/${conversationId}/api`
|
|
284
|
+
: 'http://localhost:10086/api';
|
|
285
|
+
const backendUrl = `http://localhost:${process.env.NJS_SERVER_PORT || '3000'}`;
|
|
286
|
+
const withProjectDomain = (urlPath) => {
|
|
287
|
+
if (isCloudEnv && process.env.NODE_ENV === 'production') {
|
|
288
|
+
return `https://ma.zijieapi.com${urlPath}`;
|
|
289
|
+
}
|
|
290
|
+
if (isCloudEnv && process.env.NODE_ENV === 'development') {
|
|
291
|
+
return `${cloudDevProjectDomain}${urlPath}`;
|
|
292
|
+
}
|
|
293
|
+
return `http://localhost:10086${urlPath}`;
|
|
294
|
+
};
|
|
295
|
+
const aioServerUrl = new URL(aioServerPath);
|
|
296
|
+
const PROJECT_DOMAIN = process.env.PROJECT_DOMAIN || withProjectDomain(aioServerUrl.pathname);
|
|
297
|
+
const UPLOAD_URL = process.env.UPLOAD_URL || withProjectDomain(`/api/apps/open_ai_coding_chat_server/aio_server/${conversationId}/v1/file/upload`);
|
|
298
|
+
const DOWNLOAD_URL = process.env.DOWNLOAD_URL || withProjectDomain(`/api/apps/open_ai_coding_chat_server/aio_server/${conversationId}/v1/file/download?path=`);
|
|
299
|
+
const proxyConfig = isCloudEnv
|
|
300
|
+
? {
|
|
301
|
+
[aioServerPath]: {
|
|
302
|
+
target: backendUrl,
|
|
303
|
+
changeOrigin: true,
|
|
304
|
+
secure: false,
|
|
305
|
+
rewrite: (requestPath) => {
|
|
306
|
+
const rest = requestPath.replace(aioServerPath, '');
|
|
307
|
+
return rest.startsWith('/api') ? rest : `/api${rest}`;
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
}
|
|
311
|
+
: {
|
|
312
|
+
'/api': { target: backendUrl, changeOrigin: true, secure: false },
|
|
313
|
+
};
|
|
314
|
+
const devConfig = {
|
|
315
|
+
logger: { quiet: false, stats: true },
|
|
316
|
+
mini: {},
|
|
317
|
+
h5: {
|
|
318
|
+
publicPath: isCloudEnv ? `${previewBasePath}/` : '/',
|
|
319
|
+
router: isCloudEnv
|
|
320
|
+
? { mode: 'browser', basename: previewBasePath }
|
|
321
|
+
: { mode: 'hash' },
|
|
322
|
+
devServer: {
|
|
323
|
+
port: 10086,
|
|
324
|
+
open: false,
|
|
325
|
+
...{ hmr: false },
|
|
326
|
+
proxy: proxyConfig,
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
const prodConfig = {
|
|
331
|
+
mini: {},
|
|
332
|
+
cache: { enable: true },
|
|
333
|
+
h5: {},
|
|
334
|
+
};
|
|
335
|
+
const appConfigPath = path.join(srcDir, "app.config.ts");
|
|
336
|
+
// 保存 Taro 常驻编译上下文的引用,用于刷新 app/pages 与重置 loaderMeta。
|
|
337
|
+
let taroCompilerContext;
|
|
338
|
+
const isAppEntry = createAppEntryMatcher(srcDir);
|
|
339
|
+
const injectedViteErrorReporter = buildInjectedViteErrorReporter(viteErrorTargets);
|
|
340
|
+
// dev(watch 模式)下 tt 产物输出到 dist,
|
|
341
|
+
// 与 build:tt(NODE_ENV=production)的 dist-tt 区分开。
|
|
342
|
+
const isDevBuild = process.env.NODE_ENV === 'development';
|
|
343
|
+
const injectedRouteHealer = buildInjectedRouteHealer();
|
|
344
|
+
const isTt = process.env.TARO_ENV === 'tt';
|
|
345
|
+
const shouldRefreshAppConfigOnUpdate = isH5 || isTt;
|
|
346
|
+
let shouldRefreshTtConfig = false;
|
|
347
|
+
const refreshTaroCompilerContext = (ctx, options = {}) => {
|
|
348
|
+
if (!ctx) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
if (options.resetLoaderMeta) {
|
|
352
|
+
ctx.loaderMeta = undefined;
|
|
353
|
+
}
|
|
354
|
+
// 原地更新,保持 app 对象 / pages 数组引用(下游插件闭包持有)。
|
|
355
|
+
if (typeof ctx.getApp === "function" && ctx.app) {
|
|
356
|
+
Object.assign(ctx.app, ctx.getApp());
|
|
357
|
+
}
|
|
358
|
+
if (typeof ctx.getPages === "function" && Array.isArray(ctx.pages)) {
|
|
359
|
+
ctx.pages.splice(0, ctx.pages.length, ...ctx.getPages());
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
const outputRootMap = {
|
|
363
|
+
tt: isDevBuild ? 'dist' : 'dist-tt',
|
|
364
|
+
h5: 'dist-web',
|
|
365
|
+
};
|
|
366
|
+
const defaultOutputRoot = outputRootMap[process.env.TARO_ENV || ''] || 'dist';
|
|
367
|
+
const baseConfig = {
|
|
368
|
+
projectName: "microapp",
|
|
369
|
+
date: "2026-3-5",
|
|
370
|
+
designWidth: 375,
|
|
371
|
+
deviceRatio: {
|
|
372
|
+
640: 2.34 / 2,
|
|
373
|
+
750: 1,
|
|
374
|
+
375: 2,
|
|
375
|
+
828: 1.81 / 2,
|
|
376
|
+
},
|
|
377
|
+
sourceRoot: "src",
|
|
378
|
+
outputRoot: defaultOutputRoot,
|
|
379
|
+
alias: {
|
|
380
|
+
"@": srcDir,
|
|
381
|
+
// TT collects used native components from plugin-inject's export barrel.
|
|
382
|
+
// Resolve the public SDK component there so it survives template pruning.
|
|
383
|
+
...(isTt ? {
|
|
384
|
+
'@open-dy/vibecoding-sdk-taro/components/miniapp-open-card': '@tarojs/plugin-inject/dist/components-react',
|
|
385
|
+
} : {}),
|
|
386
|
+
"lucide-taro": fs.existsSync(legacyIconEntry)
|
|
387
|
+
? legacyIconEntry
|
|
388
|
+
: '@open-dy/lucide-taro',
|
|
389
|
+
},
|
|
390
|
+
plugins: [
|
|
391
|
+
[
|
|
392
|
+
path.resolve(SDK_DIR, "plugins/app-config.cjs"),
|
|
393
|
+
{ previewBasePath }
|
|
394
|
+
],
|
|
395
|
+
[
|
|
396
|
+
"@tarojs/plugin-inject", // 注入抖音小程序的一些原生事件
|
|
397
|
+
{
|
|
398
|
+
components: {
|
|
399
|
+
// Registers the host-side MiniappOpenCard mapping. Business code
|
|
400
|
+
// imports MiniappOpenCard from the Taro SDK; its props,
|
|
401
|
+
// domain rules, and rendering requirements live in the Skill
|
|
402
|
+
// reference rather than in this build-only plugin configuration.
|
|
403
|
+
MiniappOpenCard: {
|
|
404
|
+
'app-id': JSON.stringify(OPEN_CARD_ID),
|
|
405
|
+
path: '',
|
|
406
|
+
'init-data': '',
|
|
407
|
+
'env-version': '',
|
|
408
|
+
bindLoad: '',
|
|
409
|
+
bindError: '',
|
|
410
|
+
},
|
|
411
|
+
Button: {
|
|
412
|
+
'bindaddshortcut': '', // 注入 bindaddshortcut 事件,当openType为addShortcut时回调触发
|
|
413
|
+
'data-video-id': '', // 注入 data-video-id 属性,当openType为navigateToVideoView时,指定跳转的视频id
|
|
414
|
+
'data-video-type': '', // 注入 data-video-type 属性,当openType为navigateToVideoView时,指定跳转的视频类型
|
|
415
|
+
'bindnavigatetovideoview': '', // 注入 bindnavigatetovideoview 事件,当openType为navigateToVideoView时回调触发
|
|
416
|
+
},
|
|
417
|
+
ChannelVideo: {
|
|
418
|
+
'item-id': '',
|
|
419
|
+
'item-id-type': "'raw'",
|
|
420
|
+
autoplay: 'false',
|
|
421
|
+
loop: 'false',
|
|
422
|
+
'object-fit': "'contain'",
|
|
423
|
+
preload: 'false',
|
|
424
|
+
bindplay: '',
|
|
425
|
+
bindpause: '',
|
|
426
|
+
bindwaiting: '',
|
|
427
|
+
bindstop: '',
|
|
428
|
+
bindend: '',
|
|
429
|
+
bindprogress: '',
|
|
430
|
+
binderror: '',
|
|
431
|
+
},
|
|
432
|
+
},
|
|
433
|
+
componentsMap: {
|
|
434
|
+
MiniappOpenCard: "miniapp-open-card",
|
|
435
|
+
ChannelVideo: 'channel-video',
|
|
436
|
+
},
|
|
437
|
+
voidComponents: ['channel-video'],
|
|
438
|
+
}
|
|
439
|
+
],
|
|
440
|
+
],
|
|
441
|
+
defineConstants: {
|
|
442
|
+
PROJECT_DOMAIN: JSON.stringify(PROJECT_DOMAIN),
|
|
443
|
+
DOUYIN_CLOUD_ENV_ID: JSON.stringify(DOUYIN_CLOUD_ENV_ID),
|
|
444
|
+
DOUYIN_CLOUD_DEV_ENV_ID: JSON.stringify(DOUYIN_CLOUD_DEV_ENV_ID),
|
|
445
|
+
DOUYIN_CLOUD_SERVICE_ID: JSON.stringify(DOUYIN_CLOUD_SERVICE_ID),
|
|
446
|
+
OPEN_CARD_ID: JSON.stringify(OPEN_CARD_ID),
|
|
447
|
+
AUDIT_DOUYIN_CLOUD_ENV_ID: JSON.stringify(AUDIT_DOUYIN_CLOUD_ENV_ID),
|
|
448
|
+
AUDIT_DOUYIN_CLOUD_SERVICE_ID: JSON.stringify(AUDIT_DOUYIN_CLOUD_SERVICE_ID),
|
|
449
|
+
UPLOAD_URL: JSON.stringify(UPLOAD_URL),
|
|
450
|
+
DOWNLOAD_URL: JSON.stringify(DOWNLOAD_URL),
|
|
451
|
+
},
|
|
452
|
+
copy: {
|
|
453
|
+
patterns: [],
|
|
454
|
+
options: {},
|
|
455
|
+
},
|
|
456
|
+
jsMinimizer: "esbuild",
|
|
457
|
+
framework: "react",
|
|
458
|
+
compiler: {
|
|
459
|
+
type: "vite",
|
|
460
|
+
vitePlugins: [
|
|
461
|
+
viteDependCardPlugin(),
|
|
462
|
+
viteTaroSourceLocationPlugin({
|
|
463
|
+
enabled: isDevBuild,
|
|
464
|
+
projectRoot,
|
|
465
|
+
}),
|
|
466
|
+
{
|
|
467
|
+
name: "build-sourcemap",
|
|
468
|
+
config(config) {
|
|
469
|
+
if (!isTt && !isDevBuild) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
config.build = config.build ?? {};
|
|
473
|
+
config.build.sourcemap = true;
|
|
474
|
+
if (isDevBuild) {
|
|
475
|
+
config.build.minify = false;
|
|
476
|
+
}
|
|
477
|
+
},
|
|
478
|
+
},
|
|
479
|
+
viteInlineJsonPlugin({
|
|
480
|
+
projectRoot,
|
|
481
|
+
}),
|
|
482
|
+
viteImageAssetImportPlugin({
|
|
483
|
+
projectRoot,
|
|
484
|
+
}),
|
|
485
|
+
...(isH5
|
|
486
|
+
? []
|
|
487
|
+
: [
|
|
488
|
+
UnifiedViteWeappTailwindcssPlugin({
|
|
489
|
+
rem2rpx: true,
|
|
490
|
+
cssEntries: [path.resolve(srcDir, "app.css")],
|
|
491
|
+
cssSelectorReplacement: {
|
|
492
|
+
universal: ['view', 'text', 'page'],
|
|
493
|
+
},
|
|
494
|
+
}),
|
|
495
|
+
]),
|
|
496
|
+
{
|
|
497
|
+
name: "postcss-config-loader-plugin",
|
|
498
|
+
config(config) {
|
|
499
|
+
if (typeof config.css?.postcss === "object") {
|
|
500
|
+
config.css?.postcss.plugins?.unshift(tailwindcss());
|
|
501
|
+
}
|
|
502
|
+
},
|
|
503
|
+
},
|
|
504
|
+
{
|
|
505
|
+
// Avoid a separate pre-bundled lucide-taro chunk in H5 dev.
|
|
506
|
+
name: "lucide-taro-alias-fix",
|
|
507
|
+
config(config) {
|
|
508
|
+
config.optimizeDeps = config.optimizeDeps ?? {};
|
|
509
|
+
config.optimizeDeps.exclude = [...new Set([
|
|
510
|
+
...(config.optimizeDeps.exclude ?? []),
|
|
511
|
+
"lucide-taro",
|
|
512
|
+
"@open-dy/lucide-taro",
|
|
513
|
+
])];
|
|
514
|
+
},
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
name: "cloud-preview-hmr-path",
|
|
518
|
+
config() {
|
|
519
|
+
if (!isH5 || !previewBasePath) {
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
return {
|
|
523
|
+
server: {
|
|
524
|
+
hmr: {
|
|
525
|
+
path: `/ws`,
|
|
526
|
+
},
|
|
527
|
+
},
|
|
528
|
+
};
|
|
529
|
+
},
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
name: "allow-all-hosts",
|
|
533
|
+
configureServer(server) {
|
|
534
|
+
server.config.server.allowedHosts = true;
|
|
535
|
+
},
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
name: "vite-optimized-deps-no-cache",
|
|
539
|
+
configureServer(server) {
|
|
540
|
+
if (!isH5 || process.env.NODE_ENV === "production") {
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
server.middlewares.use((req, res, next) => {
|
|
544
|
+
if (!isViteOptimizedDepsRequest(req.url)) {
|
|
545
|
+
return next();
|
|
546
|
+
}
|
|
547
|
+
const originalSetHeader = res.setHeader.bind(res);
|
|
548
|
+
res.setHeader = ((name, value) => {
|
|
549
|
+
if (name.toLowerCase() === "cache-control") {
|
|
550
|
+
return originalSetHeader(name, "no-cache");
|
|
551
|
+
}
|
|
552
|
+
return originalSetHeader(name, value);
|
|
553
|
+
});
|
|
554
|
+
next();
|
|
555
|
+
});
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
name: "preview-history-fallback",
|
|
560
|
+
configureServer(server) {
|
|
561
|
+
server.middlewares.use((req, res, next) => {
|
|
562
|
+
if (!shouldRewritePreviewRequest(req)) {
|
|
563
|
+
return next();
|
|
564
|
+
}
|
|
565
|
+
if (previewBasePath &&
|
|
566
|
+
req.url?.startsWith(previewBasePath) &&
|
|
567
|
+
!req.url.startsWith(`${previewBasePath}/ws`) &&
|
|
568
|
+
!req.url.includes("/@vite/") &&
|
|
569
|
+
!/\.[a-zA-Z0-9]+($|\?)/.test(req.url)) {
|
|
570
|
+
const urlObj = new URL(req.url, `http://${req.headers.host}`);
|
|
571
|
+
urlObj.pathname = `${previewBasePath}/`;
|
|
572
|
+
req.url = urlObj.pathname + urlObj.search;
|
|
573
|
+
}
|
|
574
|
+
next();
|
|
575
|
+
});
|
|
576
|
+
},
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
// app.config 改动需重建路由/入口,普通 HMR 无效。Taro 常驻
|
|
580
|
+
// viteCompilerContext 的 app/pages 在进程启动时定死,因此要在同一
|
|
581
|
+
// context 上原地刷新 app/pages。H5 侧仍触发 dev server 重启,并重置
|
|
582
|
+
// loaderMeta(规避 taro-react 字符串拼接累积导致的 React import 重复)。
|
|
583
|
+
// tt 侧显式 watch app.config.ts,页面配置由 Taro 自身监听。
|
|
584
|
+
// 两者变化时都在下一轮编译前刷新 context,让 JSON 和页面 JS 使用新配置。
|
|
585
|
+
name: "refresh-on-app-config-change",
|
|
586
|
+
async buildStart() {
|
|
587
|
+
if (!shouldRefreshAppConfigOnUpdate) {
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
if (isTt && this.meta.watchMode) {
|
|
591
|
+
this.addWatchFile(appConfigPath);
|
|
592
|
+
}
|
|
593
|
+
try {
|
|
594
|
+
const info = await this.load({ id: "taro:compiler" });
|
|
595
|
+
const ctx = info?.meta?.viteCompilerContext;
|
|
596
|
+
if (ctx) {
|
|
597
|
+
taroCompilerContext = ctx;
|
|
598
|
+
if (isTt && this.meta.watchMode && shouldRefreshTtConfig) {
|
|
599
|
+
refreshTaroCompilerContext(ctx);
|
|
600
|
+
shouldRefreshTtConfig = false;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
catch {
|
|
605
|
+
// 取不到时静默降级。
|
|
606
|
+
}
|
|
607
|
+
},
|
|
608
|
+
watchChange(id) {
|
|
609
|
+
if (!isTt || !this.meta.watchMode) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
const configPath = path.normalize(id.split("?")[0].split("#")[0]);
|
|
613
|
+
const isPageConfig = taroCompilerContext?.pages?.some((page) => typeof page?.configPath === "string" &&
|
|
614
|
+
path.normalize(page.configPath) === configPath);
|
|
615
|
+
if (configPath === path.normalize(appConfigPath) || isPageConfig) {
|
|
616
|
+
shouldRefreshTtConfig = true;
|
|
617
|
+
}
|
|
618
|
+
},
|
|
619
|
+
handleHotUpdate({ file, server }) {
|
|
620
|
+
if (!isH5) {
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
if (file === appConfigPath) {
|
|
624
|
+
server.config.logger.info("[refresh-on-app-config-change] app.config 变化,重启 dev server...", { timestamp: true });
|
|
625
|
+
const ctx = taroCompilerContext;
|
|
626
|
+
if (ctx) {
|
|
627
|
+
try {
|
|
628
|
+
refreshTaroCompilerContext(ctx, { resetLoaderMeta: true });
|
|
629
|
+
}
|
|
630
|
+
catch {
|
|
631
|
+
// 刷新失败时退回到「仅重启」。
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
server.restart();
|
|
635
|
+
return [];
|
|
636
|
+
}
|
|
637
|
+
},
|
|
638
|
+
},
|
|
639
|
+
networkUrlAnalyzerPlugin(srcDir),
|
|
640
|
+
{
|
|
641
|
+
name: "inject-dev-scripts",
|
|
642
|
+
transform(code, id) {
|
|
643
|
+
if (!isH5 || process.env.NODE_ENV === "production") {
|
|
644
|
+
return null;
|
|
645
|
+
}
|
|
646
|
+
if (!isAppEntry(id)) {
|
|
647
|
+
return null;
|
|
648
|
+
}
|
|
649
|
+
return `${code}\n${injectedViteErrorReporter}\n${injectedRouteHealer}`;
|
|
650
|
+
},
|
|
651
|
+
transformIndexHtml(html) {
|
|
652
|
+
if (!isH5 || process.env.NODE_ENV === "production") {
|
|
653
|
+
return html;
|
|
654
|
+
}
|
|
655
|
+
return html.replace("</head>", ` <script>window.__CONSOLE_BRIDGE_CONFIG__ = Object.assign({}, window.__CONSOLE_BRIDGE_CONFIG__, { appType: "microapp" });</script>\n <script src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_wwhpupt_ylwvslclk/ljhwZthlaukjlkulzlp/vibe-coding-inject/console-proxy.js?t=${Date.now()}"></script>\n <script src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_wwhpupt_ylwvslclk/ljhwZthlaukjlkulzlp/vibe-coding-inject/vite-overlay-observer.js?t=${Date.now()}"></script>\n</head>`);
|
|
656
|
+
},
|
|
657
|
+
},
|
|
658
|
+
],
|
|
659
|
+
},
|
|
660
|
+
cache: {
|
|
661
|
+
enable: true, // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
|
|
662
|
+
},
|
|
663
|
+
mini: {
|
|
664
|
+
postcss: {
|
|
665
|
+
pxtransform: {
|
|
666
|
+
enable: true,
|
|
667
|
+
config: {},
|
|
668
|
+
},
|
|
669
|
+
cssModules: {
|
|
670
|
+
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
|
|
671
|
+
config: {
|
|
672
|
+
namingPattern: "module", // 转换模式,取值为 global/module
|
|
673
|
+
generateScopedName: "[name]__[local]___[hash:base64:5]",
|
|
674
|
+
},
|
|
675
|
+
},
|
|
676
|
+
},
|
|
677
|
+
},
|
|
678
|
+
h5: {
|
|
679
|
+
publicPath: "/",
|
|
680
|
+
staticDirectory: "static",
|
|
681
|
+
miniCssExtractPluginOption: {
|
|
682
|
+
ignoreOrder: true,
|
|
683
|
+
filename: "css/[name].[hash].css",
|
|
684
|
+
chunkFilename: "css/[name].[chunkhash].css",
|
|
685
|
+
},
|
|
686
|
+
postcss: {
|
|
687
|
+
autoprefixer: {
|
|
688
|
+
enable: true,
|
|
689
|
+
config: {},
|
|
690
|
+
},
|
|
691
|
+
cssModules: {
|
|
692
|
+
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
|
|
693
|
+
config: {
|
|
694
|
+
namingPattern: "module", // 转换模式,取值为 global/module
|
|
695
|
+
generateScopedName: "[name]__[local]___[hash:base64:5]",
|
|
696
|
+
},
|
|
697
|
+
},
|
|
698
|
+
},
|
|
699
|
+
},
|
|
700
|
+
rn: {
|
|
701
|
+
appName: "taroDemo",
|
|
702
|
+
postcss: {
|
|
703
|
+
cssModules: {
|
|
704
|
+
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
|
|
705
|
+
},
|
|
706
|
+
},
|
|
707
|
+
},
|
|
708
|
+
};
|
|
709
|
+
if (process.env.NODE_ENV === "development") {
|
|
710
|
+
// 本地开发构建配置(不混淆压缩)
|
|
711
|
+
const config = merge({}, baseConfig, devConfig);
|
|
712
|
+
return applyConfigOverrides(config, options.overrides, {
|
|
713
|
+
isH5,
|
|
714
|
+
isTt,
|
|
715
|
+
mode: process.env.NODE_ENV ?? '',
|
|
716
|
+
projectRoot,
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
// 生产构建配置(默认开启压缩混淆等)
|
|
720
|
+
const config = merge({}, baseConfig, prodConfig);
|
|
721
|
+
return applyConfigOverrides(config, options.overrides, {
|
|
722
|
+
isH5,
|
|
723
|
+
isTt,
|
|
724
|
+
mode: process.env.NODE_ENV ?? '',
|
|
725
|
+
projectRoot,
|
|
726
|
+
});
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
//# sourceMappingURL=taro.js.map
|