107 lines
3.3 KiB
TypeScript
107 lines
3.3 KiB
TypeScript
import { defineConfig } from 'vite'
|
|
import react from '@vitejs/plugin-react'
|
|
import path from 'path' // Import path module
|
|
|
|
const inferChunkName = (moduleIds: string[]) => {
|
|
const joined = moduleIds.join('\n')
|
|
|
|
if (
|
|
joined.includes('/node_modules/rc-pagination/') ||
|
|
joined.includes('/node_modules/rc-table/') ||
|
|
joined.includes('/node_modules/rc-resize-observer/') ||
|
|
joined.includes('/node_modules/rc-virtual-list/')
|
|
) {
|
|
return 'antd-table'
|
|
}
|
|
if (joined.includes('/node_modules/antd/es/input') || joined.includes('/node_modules/rc-input/')) {
|
|
return 'antd-input'
|
|
}
|
|
if (joined.includes('/node_modules/antd/es/button') || joined.includes('/node_modules/rc-button/')) {
|
|
return 'antd-button'
|
|
}
|
|
if (joined.includes('/node_modules/antd/es/collapse') || joined.includes('/node_modules/rc-collapse/')) {
|
|
return 'antd-collapse'
|
|
}
|
|
if (joined.includes('/node_modules/antd/es/skeleton')) {
|
|
return 'antd-skeleton'
|
|
}
|
|
if (joined.includes('/node_modules/antd/es/grid') || joined.includes('/node_modules/antd/es/row')) {
|
|
return 'antd-grid'
|
|
}
|
|
if (joined.includes('/node_modules/antd/es/locale') || joined.includes('/node_modules/antd/locale/')) {
|
|
return 'antd-locale'
|
|
}
|
|
if (joined.includes('/node_modules/@ant-design/icons/') || joined.includes('/node_modules/@ant-design/icons-svg/')) {
|
|
return 'antd-icons'
|
|
}
|
|
if (joined.includes('/src/components/')) {
|
|
return 'app-components'
|
|
}
|
|
if (joined.includes('/src/utils/')) {
|
|
return 'app-utils'
|
|
}
|
|
|
|
return 'shared'
|
|
}
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig({
|
|
// base: '/pms-react-new/', // Set base URL if deploying to a sub-path
|
|
plugins: [react()],
|
|
resolve: { // Add resolve configuration
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src'), // Alias @ to ./src
|
|
},
|
|
},
|
|
build: {
|
|
rollupOptions: {
|
|
output: {
|
|
chunkFileNames(chunkInfo) {
|
|
const moduleIds = chunkInfo.moduleIds ?? []
|
|
const chunkName = chunkInfo.name === 'index' ? inferChunkName(moduleIds) : chunkInfo.name
|
|
return `assets/${chunkName}-[hash].js`
|
|
},
|
|
manualChunks(id) {
|
|
if (!id.includes('node_modules')) {
|
|
return undefined;
|
|
}
|
|
if (/node_modules\/(react|react-dom|scheduler)\//.test(id)) {
|
|
return 'react-vendor';
|
|
}
|
|
if (/node_modules\/(@ant-design\/icons|@ant-design\/icons-svg)\//.test(id)) {
|
|
return 'antd-icons';
|
|
}
|
|
if (/node_modules\/(rc-table|rc-pagination|rc-resize-observer|rc-virtual-list)\//.test(id)) {
|
|
return 'antd-table';
|
|
}
|
|
if (/node_modules\/echarts-for-react\//.test(id)) {
|
|
return 'echarts-react';
|
|
}
|
|
if (/node_modules\/zrender\//.test(id)) {
|
|
return 'zrender-vendor';
|
|
}
|
|
if (/node_modules\/echarts\//.test(id)) {
|
|
return 'echarts-vendor';
|
|
}
|
|
if (/node_modules\/(react-router|react-router-dom)\//.test(id)) {
|
|
return 'router-vendor';
|
|
}
|
|
if (/node_modules\/dayjs\//.test(id)) {
|
|
return 'dayjs-vendor';
|
|
}
|
|
return undefined;
|
|
},
|
|
},
|
|
},
|
|
},
|
|
server: {
|
|
proxy: {
|
|
'/api': {
|
|
target: 'http://127.0.0.1:8080',
|
|
changeOrigin: true,
|
|
rewrite: (path) => path.replace(/^\/api/, '')
|
|
}
|
|
}
|
|
}
|
|
})
|