101 lines
3.3 KiB
JavaScript
101 lines
3.3 KiB
JavaScript
import { defineConfig } from 'vite'
|
|
import react from '@vitejs/plugin-react'
|
|
import process from 'node:process'
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig({
|
|
plugins: [react()],
|
|
build: {
|
|
// Clean stale chunks, including retired feature bundles.
|
|
emptyOutDir: true,
|
|
cssCodeSplit: false,
|
|
modulePreload: false,
|
|
rollupOptions: {
|
|
output: {
|
|
entryFileNames: 'assets/[name]-[hash].js',
|
|
chunkFileNames(chunkInfo) {
|
|
if (chunkInfo.name === 'app-shell') return 'assets/app-shell-[hash].js'
|
|
if (chunkInfo.name === 'app-api') return 'assets/app-api-[hash].js'
|
|
if (chunkInfo.name === 'react-vendor') return 'assets/react-vendor-[hash].js'
|
|
if (chunkInfo.name === 'antd-vendor') return 'assets/antd-vendor-[hash].js'
|
|
if (chunkInfo.name === 'charts-vendor') return 'assets/charts-vendor-[hash].js'
|
|
if (chunkInfo.name === 'data-vendor') return 'assets/data-vendor-[hash].js'
|
|
return 'assets/[name]-[hash].js'
|
|
},
|
|
assetFileNames(assetInfo) {
|
|
if (assetInfo.name?.endsWith('.css')) {
|
|
return 'assets/style-[hash][extname]'
|
|
}
|
|
return 'assets/[name]-[hash][extname]'
|
|
},
|
|
manualChunks(id) {
|
|
const normalizedId = id.replace(/\\/g, '/')
|
|
|
|
if (normalizedId.includes('node_modules') || normalizedId.includes('/.vite/deps/')) {
|
|
if (
|
|
normalizedId.includes('/react/') ||
|
|
normalizedId.includes('react-dom') ||
|
|
normalizedId.includes('react-router') ||
|
|
normalizedId.includes('@remix-run/router') ||
|
|
normalizedId.includes('react_jsx-runtime') ||
|
|
normalizedId.includes('scheduler')
|
|
) {
|
|
return 'react-vendor'
|
|
}
|
|
|
|
if (
|
|
normalizedId.includes('antd') ||
|
|
normalizedId.includes('@ant-design') ||
|
|
normalizedId.includes('@ant-design/pro-components') ||
|
|
normalizedId.includes('/rc-')
|
|
) {
|
|
return 'antd-vendor'
|
|
}
|
|
|
|
if (
|
|
normalizedId.includes('echarts') ||
|
|
normalizedId.includes('zrender') ||
|
|
normalizedId.includes('recharts')
|
|
) {
|
|
return 'charts-vendor'
|
|
}
|
|
|
|
if (
|
|
normalizedId.includes('axios') ||
|
|
normalizedId.includes('@cubejs-client')
|
|
) {
|
|
return 'data-vendor'
|
|
}
|
|
|
|
return 'vendor'
|
|
}
|
|
|
|
if (normalizedId.includes('/src/api/')) return 'app-api'
|
|
if (normalizedId.includes('/src/constants/')) return 'app-shell'
|
|
if (normalizedId.includes('/src/layouts/')) return 'app-shell'
|
|
if (
|
|
normalizedId.includes('/src/components/AppVersionGuard.jsx') ||
|
|
normalizedId.includes('/src/components/ErrorBoundary.jsx')
|
|
) {
|
|
return 'app-shell'
|
|
}
|
|
|
|
return undefined
|
|
},
|
|
},
|
|
},
|
|
},
|
|
server: {
|
|
proxy: {
|
|
'/api': {
|
|
target: process.env.VITE_API_PROXY_TARGET || 'http://localhost:4001',
|
|
changeOrigin: true,
|
|
},
|
|
'/cubejs-api': {
|
|
target: process.env.VITE_API_PROXY_TARGET || 'http://localhost:4001',
|
|
changeOrigin: true,
|
|
},
|
|
},
|
|
},
|
|
})
|