refactor: vite.config.ts 类型修复与 Vite 8 迁移适配
- 修复 vite.config.ts 中 command 隐式 any 类型错误 - 修复 proxy 中 path 参数隐式 any 类型错误 - 将无效的 oxc.drop 配置迁移为 Vite 8 原生方式(build.rolldownOptions.output.minify.compress) - 引入 defineConfig + ConfigEnv 提供完整类型推导 - JS 文件迁移为 TypeScript(user.ts, routerGuard.ts 等) - 更新 API 层类型定义
This commit is contained in:
@@ -3,11 +3,12 @@ import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||
import { resolve } from 'path'
|
||||
import Components from 'unplugin-vue-components/vite'
|
||||
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
|
||||
import { defineConfig, type ConfigEnv } from 'vite'
|
||||
|
||||
// import { viteSingleFile } from 'vite-plugin-singlefile'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default ({ command }) => {
|
||||
export default defineConfig(({ command }: ConfigEnv) => {
|
||||
const isBuild = command === 'build'
|
||||
return ({
|
||||
plugins: [
|
||||
@@ -32,7 +33,7 @@ export default ({ command }) => {
|
||||
'/api': {
|
||||
target: `http://127.0.0.1:16003/`,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, '')
|
||||
rewrite: (path: string) => path.replace(/^\/api/, '')
|
||||
},
|
||||
'/ws': {
|
||||
target: `ws://192.168.3.110:16003/`,
|
||||
@@ -41,9 +42,18 @@ export default ({ command }) => {
|
||||
}
|
||||
}
|
||||
},
|
||||
oxc: {
|
||||
//清除全局的console.log和debug
|
||||
drop: isBuild ? ['console', 'debugger'] : [],
|
||||
}
|
||||
// Vite 8 原生方式:使用 Oxc Minifier 的 drop 选项
|
||||
build: {
|
||||
rolldownOptions: {
|
||||
output: {
|
||||
minify: {
|
||||
compress: {
|
||||
dropConsole: isBuild,
|
||||
dropDebugger: isBuild,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user