You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WXCampusFoodOrdering/order-system/vite.config.ts

53 lines
1.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/// <reference types="vite/client" />
/// <reference types="@vitejs/plugin-vue" />
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path' //导入nodejs核心模块path解构提取resolce方法
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
console.log('加载的环境变量:', loadEnv(mode, process.cwd()))
return {
define: {
// 替换为全局变量
__APP_BASE_URL__: JSON.stringify("http://localhost:8089"),
},
plugins: [vue()],
server: {
host: '0.0.0.0',//解决控制台Network:use--host to expose
port: 8080,//配置端口号
hmr: true,//开启热更新
open: true,//启动在浏览器打开
// 跨域配置,所有api的请求都会被转接到后端接口
proxy: {
'/api': { // 这里也匹配 /api 路径
target: 'http://localhost:8089',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}
}
},
// resolve: {
// //为项目设置别名,简化项目路径
// alias: [
// {
// find: '@',
// replacement: resolve(__dirname, 'src')
// }
// ]
// }
resolve: {
// 修正为对象格式
alias: {
'@': path.resolve(__dirname, 'src'),
// 可以添加更多别名
'components': path.resolve(__dirname, 'src/components')
},
// 添加扩展名支持
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
},
build: {
chunkSizeWarningLimit: 1500
}
}
})