mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
118 lines
3.2 KiB
TypeScript
118 lines
3.2 KiB
TypeScript
import { defineConfig } from 'vite'
|
|
import react from '@vitejs/plugin-react'
|
|
import { VitePWA } from 'vite-plugin-pwa'
|
|
import { resolve } from 'node:path'
|
|
import { APP_VERSION } from '@hapi/protocol/buildInfo'
|
|
|
|
const base = process.env.VITE_BASE_URL || '/'
|
|
const hubTarget = process.env.VITE_HUB_PROXY || 'http://127.0.0.1:3006'
|
|
|
|
function getVendorChunkName(id: string): string | undefined {
|
|
if (!id.includes('/node_modules/')) {
|
|
return undefined
|
|
}
|
|
|
|
if (id.includes('/node_modules/@xterm/')) {
|
|
return 'vendor-terminal'
|
|
}
|
|
|
|
if (
|
|
id.includes('/node_modules/@assistant-ui/')
|
|
|| id.includes('/node_modules/remark-gfm/')
|
|
|| id.includes('/node_modules/hast-util-to-jsx-runtime/')
|
|
) {
|
|
return 'vendor-assistant'
|
|
}
|
|
|
|
if (id.includes('/node_modules/@elevenlabs/react/')) {
|
|
return 'vendor-voice'
|
|
}
|
|
|
|
return undefined
|
|
}
|
|
|
|
export default defineConfig({
|
|
define: {
|
|
__APP_VERSION__: JSON.stringify(APP_VERSION),
|
|
},
|
|
server: {
|
|
host: true,
|
|
allowedHosts: ['hapidev.weishu.me'],
|
|
proxy: {
|
|
'/api': {
|
|
target: hubTarget,
|
|
changeOrigin: true
|
|
},
|
|
'/socket.io': {
|
|
target: hubTarget,
|
|
ws: true
|
|
}
|
|
}
|
|
},
|
|
plugins: [
|
|
react(),
|
|
VitePWA({
|
|
registerType: 'autoUpdate',
|
|
includeAssets: ['favicon.ico', 'apple-touch-icon-180x180.png', 'mask-icon.svg'],
|
|
strategies: 'injectManifest',
|
|
srcDir: 'src',
|
|
filename: 'sw.ts',
|
|
manifest: {
|
|
name: 'HAPI',
|
|
short_name: 'HAPI',
|
|
description: 'AI-powered development assistant',
|
|
theme_color: '#ffffff',
|
|
background_color: '#ffffff',
|
|
display: 'standalone',
|
|
orientation: 'portrait',
|
|
scope: base,
|
|
start_url: base,
|
|
icons: [
|
|
{
|
|
src: 'pwa-64x64.png',
|
|
sizes: '64x64',
|
|
type: 'image/png',
|
|
purpose: 'any'
|
|
},
|
|
{
|
|
src: 'pwa-192x192.png',
|
|
sizes: '192x192',
|
|
type: 'image/png',
|
|
purpose: 'any'
|
|
},
|
|
{
|
|
src: 'pwa-512x512.png',
|
|
sizes: '512x512',
|
|
type: 'image/png',
|
|
purpose: 'any'
|
|
}
|
|
]
|
|
},
|
|
injectManifest: {
|
|
globPatterns: ['**/*.{js,css,html,ico,png,svg,woff,woff2}']
|
|
},
|
|
devOptions: {
|
|
enabled: true,
|
|
type: 'module'
|
|
}
|
|
})
|
|
],
|
|
base,
|
|
resolve: {
|
|
alias: {
|
|
'@': resolve(__dirname, 'src')
|
|
}
|
|
},
|
|
build: {
|
|
outDir: 'dist',
|
|
emptyOutDir: true,
|
|
rollupOptions: {
|
|
output: {
|
|
manualChunks(id) {
|
|
return getVendorChunkName(id)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|