111 lines
3.2 KiB
TypeScript
111 lines
3.2 KiB
TypeScript
import { defineConfig } from '@vben/vite-config';
|
|
|
|
const DEV_CONSOLE_PREFIX = '/console';
|
|
const DEV_API_INTERNAL_PREFIX = '/__dev_api_internal__';
|
|
const DEV_API_PROD_PREFIX = '/__dev_api_prod__';
|
|
const DEV_INTERNAL_CONSOLE_TARGET = 'http://127.0.0.1:2700';
|
|
const DEV_INTERNAL_GOLANG_TARGET = 'http://127.0.0.1:2900';
|
|
const DEV_PROD_TARGET = 'https://yumiadmin-acc.global-interaction.com';
|
|
|
|
function getBundledAssetFileName(assetInfo: {
|
|
name?: string;
|
|
names?: string[];
|
|
}) {
|
|
const names = [
|
|
assetInfo.name,
|
|
...(Array.isArray(assetInfo.names) ? assetInfo.names : []),
|
|
]
|
|
.filter(Boolean)
|
|
.join(',');
|
|
|
|
if (names.endsWith('.css') || names.includes('.css,')) {
|
|
return 'css/app.css';
|
|
}
|
|
|
|
return '[ext]/[name]-[hash].[ext]';
|
|
}
|
|
|
|
function addBuildTimestampToBundledAssets() {
|
|
const buildTimestamp = Date.now().toString();
|
|
|
|
return {
|
|
name: 'chatapp-build-asset-timestamp',
|
|
transformIndexHtml(html: string) {
|
|
return html
|
|
.replaceAll('/js/app.js"', `/js/app.js?v=${buildTimestamp}"`)
|
|
.replaceAll('/css/app.css"', `/css/app.css?v=${buildTimestamp}"`);
|
|
},
|
|
};
|
|
}
|
|
|
|
function createPrefixRegExp(prefix: string) {
|
|
return new RegExp(`^${prefix.replaceAll('/', '\\/')}`);
|
|
}
|
|
|
|
export default defineConfig(async () => {
|
|
return {
|
|
application: {},
|
|
vite: {
|
|
build: {
|
|
cssCodeSplit: false,
|
|
modulePreload: false,
|
|
rolldownOptions: {
|
|
output: {
|
|
assetFileNames: getBundledAssetFileName,
|
|
chunkFileNames: 'js/[name]-[hash].js',
|
|
codeSplitting: false,
|
|
entryFileNames: 'js/app.js',
|
|
},
|
|
},
|
|
},
|
|
plugins: [addBuildTimestampToBundledAssets()],
|
|
server: {
|
|
proxy: {
|
|
[`${DEV_API_INTERNAL_PREFIX}/go`]: {
|
|
changeOrigin: true,
|
|
rewrite: (path) =>
|
|
path.replace(createPrefixRegExp(`${DEV_API_INTERNAL_PREFIX}/go`), ''),
|
|
target: DEV_INTERNAL_GOLANG_TARGET,
|
|
ws: true,
|
|
},
|
|
[DEV_API_INTERNAL_PREFIX]: {
|
|
changeOrigin: true,
|
|
rewrite: (path) =>
|
|
path.replace(createPrefixRegExp(DEV_API_INTERNAL_PREFIX), DEV_CONSOLE_PREFIX),
|
|
target: DEV_INTERNAL_CONSOLE_TARGET,
|
|
ws: true,
|
|
},
|
|
[`${DEV_API_PROD_PREFIX}/go`]: {
|
|
changeOrigin: true,
|
|
rewrite: (path) =>
|
|
path.replace(
|
|
createPrefixRegExp(`${DEV_API_PROD_PREFIX}/go`),
|
|
`${DEV_CONSOLE_PREFIX}/go`,
|
|
),
|
|
target: DEV_PROD_TARGET,
|
|
ws: true,
|
|
},
|
|
[DEV_API_PROD_PREFIX]: {
|
|
changeOrigin: true,
|
|
rewrite: (path) =>
|
|
path.replace(createPrefixRegExp(DEV_API_PROD_PREFIX), DEV_CONSOLE_PREFIX),
|
|
target: DEV_PROD_TARGET,
|
|
ws: true,
|
|
},
|
|
'/console/go': {
|
|
changeOrigin: true,
|
|
rewrite: (path) => path.replace(/^\/console\/go/, ''),
|
|
target: 'http://127.0.0.1:2900',
|
|
ws: true,
|
|
},
|
|
'/console': {
|
|
changeOrigin: true,
|
|
target: 'http://127.0.0.1:2700',
|
|
ws: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
});
|