Files
gloabl_award_front/vite.config.ts

100 lines
2.9 KiB
TypeScript
Raw Normal View History

2026-02-06 15:10:17 +08:00
import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import DefineOptions from 'unplugin-vue-define-options/vite'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'
2026-02-06 17:20:57 +08:00
import { ElementPlusResolver, AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
2026-02-06 15:10:17 +08:00
// console.log(process)
// console.log(import.meta.env.VITE_APP_URL)
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
2026-02-06 17:20:57 +08:00
const env = loadEnv(mode, process.cwd())
2026-02-06 15:10:17 +08:00
2026-02-06 17:20:57 +08:00
return {
plugins: [
vue(),
DefineOptions(),
// ...
AutoImport({
resolvers: [ElementPlusResolver()],
imports: [
'vue',
'vue-router',
{
'lodash-es': [
'debounce',
'cloneDeep',
'cloneDeepWith',
'isBoolean',
'isString',
'isNumber',
'isArray',
'isDate',
'isFunction',
'isNaN',
'isNull',
'isObject',
'isUndefined'
]
}
],
}),
Components({
resolvers: [ElementPlusResolver(), AntDesignVueResolver({ importStyle: false })]
}),
createSvgIconsPlugin({
// 指定需要缓存的图标文件夹
iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
// 指定symbolId格式
symbolId: 'icon-[dir]-[name]',
inject: 'body-last' // 注入位置优化
})
],
define: {
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false
},
css: {
preprocessorOptions: {
less: {
modifyVars: {
'primary-color': '#ec6800'
},
javascriptEnabled: true,
// 全局导入less变量文件
additionalData: `@import "${path.resolve(__dirname, 'src/assets/css/style.less')}";`
}
}
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
_c: fileURLToPath(new URL('./src/components', import.meta.url))
}
},
server: {
host: '0.0.0.0', // 允许局域网内的IP访问
2026-02-25 14:43:14 +08:00
port: 8088, // 根据环境设置端口
2026-02-06 17:20:57 +08:00
open: true, // 自动打开浏览器
strictPort: true, // 如果端口已被占用,则尝试下一个可用端口
hmr: {
overlay: true
},
proxy: {
'/api': {
//'/api'是自行设置的请求前缀
target: env.VITE_APP_URL,
changeOrigin: true, //用于控制请求头中的host值
rewrite: (path) => path.replace(/^\/api/, '/api') //路径重写正则匹配以api开头的路径为空将请求前缀删除
}
}
}
}
2026-02-06 15:10:17 +08:00
})