-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathvite.config.ts
More file actions
83 lines (77 loc) · 2.1 KB
/
Copy pathvite.config.ts
File metadata and controls
83 lines (77 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from 'path'
import { copyFileSync, existsSync, mkdirSync, readFileSync } from 'fs'
// 复制WASM文件到输出目录的函数
function copyWasmFiles() {
return {
name: 'copy-wasm-files',
writeBundle() {
const wasmFiles = [
{ src: './public/wasm/astrobox_ng_wasm.js', dest: './dist/wasm/astrobox_ng_wasm.js' },
{ src: './public/wasm/astrobox_ng_wasm_bg.wasm', dest: './dist/wasm/astrobox_ng_wasm_bg.wasm' },
{ src: './public/wasm/astrobox_ng_wasm_bg.wasm.d.ts', dest: './dist/wasm/astrobox_ng_wasm_bg.wasm.d.ts' },
{ src: './public/wasm/astrobox_ng_wasm.d.ts', dest: './dist/wasm/astrobox_ng_wasm.d.ts' },
{ src: './public/wasm-client.js', dest: './dist/wasm/wasm-client.js' }
]
// 确保目标目录存在
const wasmDir = './dist/wasm'
if (!existsSync(wasmDir)) {
mkdirSync(wasmDir, { recursive: true })
}
// 复制文件
wasmFiles.forEach(file => {
if (existsSync(file.src)) {
copyFileSync(file.src, file.dest)
console.log(`已复制: ${file.src} -> ${file.dest}`)
} else {
console.warn(`WASM文件不存在: ${file.src}`)
}
})
}
}
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
copyWasmFiles()
],
resolve: {
alias: {
'@': resolve(__dirname, './src')
}
},
server: {
port: 3000,
host: true,
fs: {
allow: [
'.' // 项目根目录
]
}
},
build: {
outDir: 'dist',
sourcemap: false,
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html')
},
output: {
manualChunks: {
vendor: ['react', 'react-dom']
}
}
},
// 确保WASM文件被正确处理
assetsInlineLimit: 0 // 不内联WASM文件
},
optimizeDeps: {
exclude: []
},
// 基础路径,如果部署在子路径下需要配置
base: './',
// 设置public目录,复制静态文件
publicDir: 'public'
})