2025-03-12 18:41:20 +08:00
|
|
|
import { fileURLToPath, URL } from 'node:url';
|
|
|
|
|
import { defineConfig, type PluginOption, loadEnv } from 'vite';
|
|
|
|
|
import vue from '@vitejs/plugin-vue';
|
|
|
|
|
import { visualizer } from "rollup-plugin-visualizer";
|
|
|
|
|
import dayjs from "dayjs";
|
|
|
|
|
import basicSSL from '@vitejs/plugin-basic-ssl';
|
|
|
|
|
import legacy from '@vitejs/plugin-legacy'
|
|
|
|
|
const fs = require('node:fs')
|
|
|
|
|
|
|
|
|
|
export default (config: any) => {
|
|
|
|
|
const env = loadEnv(config.mode, process.cwd());
|
2025-03-14 09:11:46 +08:00
|
|
|
console.log(env)
|
2025-03-12 18:41:20 +08:00
|
|
|
return defineConfig({
|
2025-03-14 09:11:46 +08:00
|
|
|
base: env.VITE_BASE_URL,
|
2025-03-12 18:41:20 +08:00
|
|
|
plugins: [
|
|
|
|
|
vue({
|
|
|
|
|
template: {
|
|
|
|
|
compilerOptions: {
|
|
|
|
|
isCustomElement: tag => /^micro-app/.test(tag)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
// 浏览器兼容性
|
|
|
|
|
legacy({
|
|
|
|
|
targets: ['defaults', 'chrome >= 78', 'safari >= 14'],
|
|
|
|
|
}),
|
|
|
|
|
visualizer({
|
|
|
|
|
open: config.mode === 'analysis',
|
|
|
|
|
}) as PluginOption,
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
server: {
|
|
|
|
|
host: true,
|
|
|
|
|
port: 443,
|
|
|
|
|
open: true, // 启动服务打开浏览器
|
|
|
|
|
headers: {
|
|
|
|
|
'Access-Control-Allow-Origin': '*',
|
2025-03-17 11:16:05 +08:00
|
|
|
},
|
|
|
|
|
proxy: {
|
|
|
|
|
// 配置跨域代理
|
2025-12-10 14:34:29 +08:00
|
|
|
'/gateway/official/u-auth': {
|
|
|
|
|
// target: 'http://223.76.236.155:20011', // 目标服务器地址
|
|
|
|
|
target: 'http://222.20.126.217:9700', // 目标服务器地址
|
|
|
|
|
changeOrigin: true, // 允许跨域
|
|
|
|
|
rewrite: (path) => path.replace('/gateway/official/u-auth', '/gateway/u-auth') // 重写路径
|
|
|
|
|
},
|
2025-03-18 15:43:07 +08:00
|
|
|
'/gateway': {
|
2025-04-16 14:36:41 +08:00
|
|
|
// target: 'http://223.76.236.155:20011', // 目标服务器地址
|
|
|
|
|
target: 'http://222.20.126.217:10010', // 目标服务器地址
|
2025-03-17 11:16:05 +08:00
|
|
|
changeOrigin: true, // 允许跨域
|
2025-03-18 15:43:07 +08:00
|
|
|
rewrite: (path) => path.replace(/^\/gateway/, '/gateway'), // 重写路径
|
2025-03-17 11:16:05 +08:00
|
|
|
}
|
2025-03-12 18:41:20 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
css: {
|
|
|
|
|
preprocessorOptions: {
|
|
|
|
|
scss: {
|
|
|
|
|
additionalData: `@import 'devui-theme/theme-collection/extend-theme-vue.scss';@import '@/assets/css/mixins/variables.scss';` // 全局引入scss文件
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
|
|
|
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
build: {
|
2025-12-05 17:12:52 +08:00
|
|
|
outDir: 'tcode', // 将打包后的文件夹名改为 openRepoPortal
|
2025-03-12 18:41:20 +08:00
|
|
|
// sourcemap: config.mode !== 'production',
|
2025-03-13 19:11:24 +08:00
|
|
|
minify: 'terser', // 确保使用 terser 进行压缩
|
|
|
|
|
terserOptions: {
|
|
|
|
|
compress: {
|
|
|
|
|
drop_console: true, // 移除 console.log
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-03-12 18:41:20 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
define: {
|
|
|
|
|
BUILD_TIME: dayjs().format('YYMMDD.HHmmss'),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
experimental: {
|
|
|
|
|
renderBuiltUrl(
|
|
|
|
|
filename: string,
|
|
|
|
|
{ hostId, hostType, type }: { hostId: string, hostType: 'js' | 'css' | 'html', type: 'public' | 'asset'; }
|
|
|
|
|
) {
|
|
|
|
|
if (type === 'asset') {
|
2025-08-26 17:52:32 +08:00
|
|
|
// return env.VITE_STATIC_HOST + '/' + filename;
|
2025-12-05 17:12:52 +08:00
|
|
|
return `/tcode/${filename}`;
|
2025-03-12 18:41:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|