From 6e2c7d5f2b377da9906d64dc902e2c900af9bac4 Mon Sep 17 00:00:00 2001 From: puke Date: Tue, 11 Feb 2025 17:14:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9post-build=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/scripts/post-build.js | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/ui/scripts/post-build.js b/ui/scripts/post-build.js index 3205337..ddfcc04 100644 --- a/ui/scripts/post-build.js +++ b/ui/scripts/post-build.js @@ -17,28 +17,35 @@ files.forEach(file => { let content = fs.readFileSync(file, 'utf-8'); if (content.includes('__vite__mapDeps')) { - // 提取原始依赖数组 - const depsMatch = content.match(/__vite__mapDeps\.viteFileDeps = \[(.*?)\]/); + // 提取新格式的依赖数组,使用非贪婪匹配 + const depsMatch = content.match(/const __vite__mapDeps=\(.*?m\.f=\[(.*?)\]/); if (depsMatch && depsMatch[1]) { const originalDeps = depsMatch[1]; - - // 替换函数实现 + + // 替换为新的实现 content = content.replace( - /function __vite__mapDeps\(indexes\) {[\s\S]*?return indexes\.map\(\(i\) => __vite__mapDeps\.viteFileDeps\[i\]\)\s*}/, - `function __vite__mapDeps(indexes) { - const apiBase = window.comfyAPI?.api?.api?.api_base; - const prefix = apiBase ? \`\${apiBase.substring(1)}/\` : ''; - if (!__vite__mapDeps.viteFileDeps) { - __vite__mapDeps.viteFileDeps = [${originalDeps}].map( - path => \`\${prefix}\${path}\` - ); - } - return indexes.map((i) => __vite__mapDeps.viteFileDeps[i]); - }` + /const __vite__mapDeps=\(.*?\)=>i\.map\(i=>d\[i\]\);/, + `const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=[${originalDeps}])))=>i.map(i=>d[i]);` ); + // 如果文件中还没有路径转换逻辑,则添加 + if (!content.includes('window.comfyAPI?.api?.api?.api_base')) { + content = content.replace( + /const __vite__mapDeps=.*?m\.f=\[(.*?)\]/, + `const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=[$1].map(path => { + const apiBase = window.comfyAPI?.api?.api?.api_base; + const prefix = apiBase ? \`\${apiBase.substring(1)}/\` : ''; + return \`\${prefix}\${path}\`; + }))))` + ); + } + fs.writeFileSync(file, content, 'utf-8'); console.log(`Modified ${path.basename(file)}`); + } else { + console.log(`No deps pattern found in ${path.basename(file)}`); } + } else { + console.log(`No __vite__mapDeps found in ${path.basename(file)}`); } }); \ No newline at end of file