86 lines
2.3 KiB
JavaScript
Executable File
86 lines
2.3 KiB
JavaScript
Executable File
import { fileURLToPath, URL } from 'node:url'
|
|
import { defineConfig, loadEnv } from 'vite'
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig(({ mode }) => {
|
|
const env = loadEnv(mode, process.cwd())
|
|
const isDev = mode === 'development'
|
|
|
|
const apiTarget = env.VITE_DEV_API_TARGET || 'https://gateway.oegame.com/shixin'
|
|
const apiProxyCommon = {
|
|
target: apiTarget,
|
|
changeOrigin: true,
|
|
secure: apiTarget.startsWith('https'),
|
|
rewrite: (path) => path.replace(/^\/api/, ''),
|
|
/** 避免 batch_link 等大请求被 dev 代理提前 504 */
|
|
timeout: 120000,
|
|
proxyTimeout: 120000,
|
|
}
|
|
|
|
return {
|
|
plugins: [vue()],
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
'/@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
},
|
|
},
|
|
server: {
|
|
host: '0.0.0.0',
|
|
port: 3000,
|
|
open: true,
|
|
proxy: {
|
|
'/api': apiProxyCommon,
|
|
'/openim-api': {
|
|
target: 'http://49.233.81.236:10002',
|
|
changeOrigin: true,
|
|
rewrite: (path) => path.replace(/^\/openim-api/, ''),
|
|
},
|
|
'/openim-chat': {
|
|
target: 'http://49.233.81.236:10008',
|
|
changeOrigin: true,
|
|
rewrite: (path) => path.replace(/^\/openim-chat/, ''),
|
|
},
|
|
'/openim-ws': {
|
|
target: 'ws://49.233.81.236:10001',
|
|
changeOrigin: true,
|
|
ws: true,
|
|
rewrite: (path) => path.replace(/^\/openim-ws/, ''),
|
|
},
|
|
},
|
|
},
|
|
base: '/',
|
|
esbuild: {
|
|
drop: isDev ? [] : ['console', 'debugger'],
|
|
},
|
|
build: {
|
|
outDir: 'dist',
|
|
assetsDir: 'assets',
|
|
sourcemap: isDev,
|
|
chunkSizeWarningLimit: 2000,
|
|
rollupOptions: {
|
|
output: {
|
|
entryFileNames: 'assets/[name]-[hash].js',
|
|
chunkFileNames: 'assets/[name]-[hash].js',
|
|
assetFileNames: 'assets/[name]-[hash].[ext]',
|
|
manualChunks: {
|
|
'vendor-vue': ['vue', 'vue-router', 'pinia'],
|
|
'vendor-element': ['element-plus'],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
css: {
|
|
preprocessorOptions: {
|
|
scss: {
|
|
additionalData: '',
|
|
},
|
|
},
|
|
},
|
|
optimizeDeps: {
|
|
include: ['vue', 'vue-router', 'pinia'],
|
|
},
|
|
}
|
|
})
|