feat: 更新依赖项,添加 PWA 插件,优化环境变量配置;调整开发服务器端口

This commit is contained in:
xiongxiao
2026-03-17 01:33:01 +08:00
committed by cnb
parent 4b1d1072b8
commit 3a4d02be75
3 changed files with 47 additions and 18 deletions

View File

@@ -5,19 +5,19 @@ import pkgs from './package.json';
import tailwindcss from '@tailwindcss/vite';
import { tanstackRouter } from '@tanstack/router-plugin/vite'
import dotenv from 'dotenv';
const config = dotenv.config().parsed || {};
console.log('Loaded .env config:', config);
const isDev = process.env.NODE_ENV === 'development';
import { VitePWA } from 'vite-plugin-pwa';
const env = dotenv.config().parsed || {};
const isDev = env.NODE_ENV === 'development' || process.env.NODE_ENV === 'development';
const basename = isDev ? '/' : pkgs?.basename || '/';
let target = config.VITE_API_URL || 'http://localhost:51515';
let target = env.VITE_API_URL || process.env.API_URL || 'http://localhost:51515';
const apiProxy = { target: target, changeOrigin: true, ws: true, rewriteWsOrigin: true, secure: false, cookieDomainRewrite: 'localhost' };
let proxy = {
'/root/': apiProxy,
'/api': apiProxy,
'/client': apiProxy,
};
console.log('API Proxy Target:', target);
/**
* @see https://vitejs.dev/config/
*/
@@ -29,7 +29,13 @@ export default defineConfig({
autoCodeSplitting: true,
}),
react(),
tailwindcss()
tailwindcss(),
VitePWA({
injectRegister: 'auto',
workbox:{
maximumFileSizeToCacheInBytes: 10 * 1024 * 1024, // 10MB
}
}),
],
resolve: {
alias: {
@@ -41,7 +47,7 @@ export default defineConfig({
BASE_NAME: JSON.stringify(basename),
},
server: {
port: 7009,
port: 7008,
host: '0.0.0.0',
allowedHosts: true,
proxy,