mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-22 16:25:51 +00:00
build: Vite 单文件构建 + 修复 doubaoime-asr 打包后 WASM 加载失败
- vite.config.ts: codeSplitting: false 替代多 chunk 输出,产出单文件 dist/cli.js - vite.config.ts: ssr.external 排除 doubaoime-asr/opus-encdec,避免 require.resolve 路径失效 - scripts/post-build.ts: 简化为直接处理单文件 dist/cli.js - src/services/doubaoSTT.ts: 改进错误信息,输出具体异常内容便于排查 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -14,20 +14,18 @@ import { execSync } from 'node:child_process'
|
|||||||
const outdir = 'dist'
|
const outdir = 'dist'
|
||||||
|
|
||||||
async function postBuild() {
|
async function postBuild() {
|
||||||
// Step 1: Patch globalThis.Bun destructuring from third-party deps
|
// Step 1: Patch globalThis.Bun destructuring in the single bundled file
|
||||||
const files = await readdir(outdir, { recursive: true })
|
const cliPath = join(outdir, 'cli.js')
|
||||||
const BUN_DESTRUCTURE = /var \{([^}]+)\} = globalThis\.Bun;?/g
|
const BUN_DESTRUCTURE = /var \{([^}]+)\} = globalThis\.Bun;?/g
|
||||||
const BUN_DESTRUCTURE_SAFE =
|
const BUN_DESTRUCTURE_SAFE =
|
||||||
'var {$1} = typeof globalThis.Bun !== "undefined" ? globalThis.Bun : {};'
|
'var {$1} = typeof globalThis.Bun !== "undefined" ? globalThis.Bun : {};'
|
||||||
|
|
||||||
let bunPatched = 0
|
let bunPatched = 0
|
||||||
for (const file of files) {
|
{
|
||||||
const filePath = join(outdir, file)
|
const content = await readFile(cliPath, 'utf-8')
|
||||||
if (typeof file !== 'string' || !file.endsWith('.js')) continue
|
|
||||||
const content = await readFile(filePath, 'utf-8')
|
|
||||||
if (BUN_DESTRUCTURE.test(content)) {
|
if (BUN_DESTRUCTURE.test(content)) {
|
||||||
await writeFile(
|
await writeFile(
|
||||||
filePath,
|
cliPath,
|
||||||
content.replace(BUN_DESTRUCTURE, BUN_DESTRUCTURE_SAFE),
|
content.replace(BUN_DESTRUCTURE, BUN_DESTRUCTURE_SAFE),
|
||||||
)
|
)
|
||||||
bunPatched++
|
bunPatched++
|
||||||
|
|||||||
@@ -110,12 +110,15 @@ export async function connectDoubaoStream(
|
|||||||
let doubaoAsr: typeof import('doubaoime-asr')
|
let doubaoAsr: typeof import('doubaoime-asr')
|
||||||
try {
|
try {
|
||||||
doubaoAsr = await import('doubaoime-asr')
|
doubaoAsr = await import('doubaoime-asr')
|
||||||
} catch {
|
} catch (err) {
|
||||||
logError(new Error('[doubao-asr] Failed to import doubaoime-asr package'))
|
logError(
|
||||||
callbacks.onError(
|
new Error(
|
||||||
'doubaoime-asr package is not installed. Install it with: bun add doubaoime-asr',
|
`[doubao-asr] Failed to import doubaoime-asr package: ${String(err)}`,
|
||||||
{ fatal: true },
|
),
|
||||||
)
|
)
|
||||||
|
callbacks.onError(`doubaoime-asr package import failed: ${String(err)}`, {
|
||||||
|
fatal: true,
|
||||||
|
})
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,11 @@ export default defineConfig({
|
|||||||
ssr: {
|
ssr: {
|
||||||
target: 'node',
|
target: 'node',
|
||||||
noExternal: true,
|
noExternal: true,
|
||||||
|
// Packages with runtime require.resolve() or WASM binaries can't be
|
||||||
|
// inlined into the bundle — they must be resolved from node_modules
|
||||||
|
// at runtime. doubaoime-asr uses opus-encdec which does
|
||||||
|
// require.resolve('opus-encdec/dist/libopus-encoder.wasm.js').
|
||||||
|
external: ['doubaoime-asr', 'opus-encdec'],
|
||||||
},
|
},
|
||||||
|
|
||||||
build: {
|
build: {
|
||||||
@@ -88,9 +93,9 @@ export default defineConfig({
|
|||||||
|
|
||||||
output: {
|
output: {
|
||||||
format: 'es',
|
format: 'es',
|
||||||
dir: 'dist',
|
// Single-file build: no code splitting, all dynamic imports inlined
|
||||||
|
codeSplitting: false,
|
||||||
entryFileNames: 'cli.js',
|
entryFileNames: 'cli.js',
|
||||||
chunkFileNames: 'chunks/[name]-[hash].js',
|
|
||||||
},
|
},
|
||||||
|
|
||||||
plugins: [
|
plugins: [
|
||||||
|
|||||||
Reference in New Issue
Block a user