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 Components from 'unplugin-vue-components/vite'
|
|
|
|
|
import { DevUiResolver } from 'unplugin-vue-components/resolvers'
|
|
|
|
|
import legacy from '@vitejs/plugin-legacy'
|
|
|
|
|
const fs = require('node:fs')
|
|
|
|
|
|
|
|
|
|
export default (config: any) => {
|
|
|
|
|
const env = loadEnv(config.mode, process.cwd());
|
|
|
|
|
return defineConfig({
|
2025-03-13 20:15:13 +08:00
|
|
|
base: '/openRepoPortal/', // 确保与 Nginx 配置匹配
|
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'],
|
|
|
|
|
}),
|
|
|
|
|
// devui组件库按需引入
|
|
|
|
|
Components({
|
|
|
|
|
resolvers: [
|
|
|
|
|
DevUiResolver({
|
|
|
|
|
importStyle: false,
|
|
|
|
|
directives: false,
|
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
}),
|
|
|
|
|
visualizer({
|
|
|
|
|
open: config.mode === 'analysis',
|
|
|
|
|
}) as PluginOption,
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
server: {
|
|
|
|
|
host: true,
|
|
|
|
|
port: 443,
|
|
|
|
|
open: true, // 启动服务打开浏览器
|
|
|
|
|
headers: {
|
|
|
|
|
'Access-Control-Allow-Origin': '*',
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
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: {
|
|
|
|
|
// 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') {
|
|
|
|
|
return env.VITE_STATIC_HOST + '/' + filename;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|