74 lines
2.6 KiB
JavaScript
74 lines
2.6 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: {
|
|
onwarn(warning, warn) {
|
|
// Manually splitting packages that depend on each other can create a circular chunk graph.
|
|
// That graph built successfully in the past but crashed before React mounted, leaving only
|
|
// the static skeleton on screen. Treat it as a release-blocking error from now on.
|
|
if (warning.code === 'CIRCULAR_CHUNK') {
|
|
throw new Error(`Circular production chunk: ${warning.message}`)
|
|
}
|
|
warn(warning)
|
|
},
|
|
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 === 'vendor') return 'assets/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/')) {
|
|
// Keep mutually dependent third-party packages in one chunk. React, Ant Design,
|
|
// charts and Cube clients share runtime helpers and cannot be split safely by path.
|
|
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,
|
|
},
|
|
},
|
|
},
|
|
})
|