Files
planet/frontend/vite.config.ts

108 lines
2.6 KiB
TypeScript

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
import fs from 'fs'
export default defineConfig({
plugins: [
react(),
{
name: 'legacy-earth',
configureServer(server) {
server.middlewares.use('/legacy/earth', (req, res, next) => {
let url = req.url || '/'
if (url === '' || url === '/') {
url = '/3dearthmult.html'
}
const filePath = path.resolve(__dirname, 'legacy/3dearthmult' + url)
if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
const ext = path.extname(filePath).toLowerCase()
const contentTypes = {
'.html': 'text/html',
'.json': 'application/json',
'.jpg': 'image/jpeg',
'.jpeg': 'image/jpeg',
'.png': 'image/png',
'.js': 'application/javascript',
'.css': 'text/css'
}
res.setHeader('Content-Type', contentTypes[ext] || 'text/plain')
fs.createReadStream(filePath).pipe(res)
} else {
next()
}
})
}
}
],
server: {
port: 3000,
proxy: {
'/api': {
target: 'http://localhost:8000',
changeOrigin: true,
secure: false,
},
'/ws': {
target: 'ws://localhost:8000',
ws: true,
changeOrigin: true,
secure: false,
},
'/health': {
target: 'http://localhost:8000',
changeOrigin: true,
secure: false,
},
},
fs: {
allow: ['..'],
},
},
publicDir: 'public',
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
optimizeDeps: {
entries: ['src/main.tsx'],
exclude: ['satellite.js'],
},
build: {
rollupOptions: {
output: {
manualChunks(id) {
if (!id.includes('node_modules')) {
return
}
if (id.includes('/@ant-design/icons/')) {
return 'icons-vendor'
}
if (
id.includes('/react/') ||
id.includes('/react-dom/') ||
id.includes('/react-router-dom/') ||
id.includes('/scheduler/')
) {
return 'react-vendor'
}
if (id.includes('/axios/')) {
return 'network-vendor'
}
if (id.includes('/three/') || id.includes('/simplex-noise/') || id.includes('/satellite.js/')) {
return 'earth-vendor'
}
},
},
},
},
})