| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- import { defineConfig } from 'vite'
- import vue from '@vitejs/plugin-vue'
- import { resolve } from 'path'
- import { OUTPUT_DIR, brotliSize, chunkSizeWarningLimit, terserOptions, rollupOptions } from './build/constant'
- import viteCompression from 'vite-plugin-compression'
- import { viteMockServe } from 'vite-plugin-mock'
- import monacoEditorPlugin from 'vite-plugin-monaco-editor'
- function pathResolve(dir: string) {
- return resolve(process.cwd(), '.', dir)
- }
- export default defineConfig({
- base: '/forge-report',
- // 修改端口
- server: {
- port: 3021,
- open: true,
- proxy: {
- // forge-report 后端接口(项目管理、AI 供应商、AI Agent、AI 对话)
- '/forge-report-api': {
- target: 'http://localhost:8581',
- changeOrigin: true,
- rewrite: (path: string) => path.replace(/^\/forge-report-api/, '/')
- },
- // LLM API 代理(阿里百炼 OpenAI 兼容接口,保留用于前端直调模式)
- '/llm': {
- target: 'https://dashscope.aliyuncs.com',
- changeOrigin: true,
- rewrite: (path: string) => path.replace(/^\/llm/, '/compatible-mode'),
- // SSE 流式代理:禁用上游 gzip 压缩以避免缓冲全量响应
- configure: (proxy) => {
- proxy.on('proxyReq', (proxyReq) => {
- proxyReq.setHeader('Accept-Encoding', 'identity')
- })
- }
- }
- }
- },
- // 路径重定向
- resolve: {
- alias: [
- {
- find: /\/#\//,
- replacement: pathResolve('types')
- },
- {
- find: '@',
- replacement: pathResolve('src')
- },
- {
- find: 'vue-i18n',
- replacement: 'vue-i18n/dist/vue-i18n.cjs.js' //解决i8n警告
- }
- ],
- dedupe: ['vue']
- },
- // 全局 css 注册
- css: {
- preprocessorOptions: {
- scss: {
- javascriptEnabled: true,
- additionalData: `@import "src/styles/common/style.scss";`
- }
- }
- },
- define: {
- // enable hydration mismatch details in production build
- __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'true'
- },
- plugins: [
- vue({
- template: {
- compilerOptions: {
- // 排除 iconify 图标影子组件编译报错
- isCustomElement: tag => tag.startsWith('iconify-icon')
- }
- }
- }),
- monacoEditorPlugin({
- languageWorkers: ['editorWorkerService', 'typescript', 'json', 'html']
- }),
- viteMockServe({
- mockPath: '/src/api/mock',
- // 开发打包开关
- localEnabled: true,
- // 生产打包开关
- prodEnabled: true,
- // 打开后,可以读取 ts 文件模块。 请注意,打开后将无法监视.js 文件
- supportTs: true,
- // 监视文件更改
- watchFiles: true
- }),
- // 压缩
- viteCompression({
- verbose: true,
- disable: false,
- threshold: 10240,
- algorithm: 'gzip',
- ext: '.gz'
- })
- ],
- build: {
- target: 'es2020',
- outDir: OUTPUT_DIR,
- // minify: 'terser', // 如果需要用terser混淆,可打开这两行
- // terserOptions: terserOptions,
- rollupOptions: rollupOptions,
- reportCompressedSize: brotliSize,
- chunkSizeWarningLimit: chunkSizeWarningLimit
- }
- })
|