107 lines
2.7 KiB
TypeScript
107 lines
2.7 KiB
TypeScript
import { defineConfig } from 'vite';
|
|
import react from '@vitejs/plugin-react';
|
|
import path from 'path';
|
|
import tailwindcss from '@tailwindcss/vite';
|
|
import basicSsl from '@vitejs/plugin-basic-ssl';
|
|
|
|
const isDev = process.env.NODE_ENV === 'development';
|
|
const unamiPlugin = {
|
|
name: 'html-transform',
|
|
transformIndexHtml(html: string) {
|
|
return html.replace(
|
|
'</head>',
|
|
`<script defer src="https://umami.xiongxiao.me/script.js" data-website-id="79e7aa98-9e6e-4eef-bc8b-9cbd0ecb11c3"></script></head>`,
|
|
);
|
|
},
|
|
};
|
|
const plugins: any[] = [basicSsl()];
|
|
if (!isDev) {
|
|
plugins.push(unamiPlugin);
|
|
}
|
|
|
|
plugins.push(tailwindcss());
|
|
const devBackend = 'https://kevisual.silkyai.cn';
|
|
// const meBackend = 'https://kevisual.xiongxiao.me';
|
|
const meBackend = 'https://kevisual.cn';
|
|
// const backend = isDev ? devBackend : meBackend;
|
|
const backendWss = devBackend.replace(/^https:/, 'wss:');
|
|
const backend = meBackend;
|
|
let proxy = {};
|
|
if (true) {
|
|
proxy = {
|
|
'/api': {
|
|
target: backend,
|
|
changeOrigin: true,
|
|
ws: true,
|
|
cookieDomainRewrite: 'localhost',
|
|
rewrite: (path: any) => path.replace(/^\/api/, '/api'),
|
|
},
|
|
'/user/login': {
|
|
target: backend,
|
|
changeOrigin: true,
|
|
cookieDomainRewrite: 'localhost',
|
|
rewrite: (path: any) => path.replace(/^\/user/, '/user'),
|
|
},
|
|
'/test': {
|
|
target: backend,
|
|
},
|
|
};
|
|
}
|
|
|
|
function processImageName(fileName: string): string {
|
|
if (fileName.includes('panda')) {
|
|
return fileName; // 保留原名
|
|
}
|
|
// 其他图片文件名处理逻辑
|
|
return `${fileName}.jpg`; // 示例:添加后缀
|
|
}
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig({
|
|
plugins: [react(), ...plugins],
|
|
|
|
css: {
|
|
postcss: {},
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src'),
|
|
},
|
|
},
|
|
define: {
|
|
DEV_SERVER: JSON.stringify(process.env.NODE_ENV === 'development'),
|
|
},
|
|
base: isDev ? '/' : '/root/center/',
|
|
build: {
|
|
rollupOptions: {
|
|
output: {
|
|
// 控制输出
|
|
// 在rollup里面, hash代表将你的文件名和文件内容进行组合计算得来的结果
|
|
assetFileNames: (chunkInfo) => {
|
|
console.log(chunkInfo.names);
|
|
if (chunkInfo.names?.includes('panda.png')) {
|
|
return '[name].[ext]';
|
|
}
|
|
return '[name].[hash].[ext]';
|
|
},
|
|
},
|
|
},
|
|
},
|
|
server: {
|
|
port: 6020,
|
|
host: '0.0.0.0',
|
|
proxy: {
|
|
'/system/lib': {
|
|
target: 'https://kevisual.xiongxiao.me',
|
|
changeOrigin: true,
|
|
},
|
|
'/api': {
|
|
target: 'https://localhost:4005',
|
|
changeOrigin: true,
|
|
rewrite: (path) => path.replace(/^\/api/, '/api'),
|
|
},
|
|
...proxy,
|
|
},
|
|
},
|
|
});
|