diff --git a/vite.config.ts b/vite.config.ts
index 495a5b4..58b3675 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -1,6 +1,6 @@
import { fileURLToPath, URL } from 'node:url'
-import { defineConfig } from 'vite'
+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'
@@ -14,58 +14,62 @@ import { VantResolver } from '@vant/auto-import-resolver'
// https://vitejs.dev/config/
-export default defineConfig({
- plugins: [
- vue(),
- DefineOptions(),
- // ...
- AutoImport({
- resolvers: [VantResolver()],
- }),
- Components({
- resolvers: [VantResolver()],
- }),
- createSvgIconsPlugin({
- // 指定需要缓存的图标文件夹
- iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
- // 指定symbolId格式
- symbolId: 'icon-[dir]-[name]',
- inject: 'body-last' // 注入位置优化
- })
- ],
- 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访问
- port: 8060, // 根据环境设置端口
- open: false, // 自动打开浏览器
- strictPort: true, // 如果端口已被占用,则尝试下一个可用端口
- hmr: {
- overlay: true
- },
- proxy: {
- '/api': {
- //'/api'是自行设置的请求前缀
- target: 'http://18.167.251.121:10095',
- changeOrigin: true, //用于控制请求头中的host值
- rewrite: (path) => path.replace(/^\/api/, '/api') //路径重写,(正则)匹配以api开头的路径为空(将请求前缀删除)
- }
- }
- }
+export default defineConfig(({ mode }) => {
+ const env = loadEnv(mode, process.cwd())
+
+ return {
+ plugins: [
+ vue(),
+ DefineOptions(),
+ // ...
+ AutoImport({
+ resolvers: [VantResolver()],
+ }),
+ Components({
+ resolvers: [VantResolver()],
+ }),
+ createSvgIconsPlugin({
+ // 指定需要缓存的图标文件夹
+ iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
+ // 指定symbolId格式
+ symbolId: 'icon-[dir]-[name]',
+ inject: 'body-last' // 注入位置优化
+ })
+ ],
+ 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访问
+ port: 8060, // 根据环境设置端口
+ open: false, // 自动打开浏览器
+ strictPort: true, // 如果端口已被占用,则尝试下一个可用端口
+ hmr: {
+ overlay: true
+ },
+ proxy: {
+ '/api': {
+ //'/api'是自行设置的请求前缀
+ target: env.VITE_APP_URL,
+ changeOrigin: true, //用于控制请求头中的host值
+ rewrite: (path) => path.replace(/^\/api/, '/api') //路径重写,(正则)匹配以api开头的路径为空(将请求前缀删除)
+ }
+ }
+ }
+ }
})