feat: enhance Vite configuration with dotenv and PWA support

- Added dotenv for environment variable management.
- Updated API URL handling to support fallback options.
- Integrated VitePWA plugin for progressive web app capabilities.
This commit is contained in:
2026-03-17 00:07:12 +08:00
parent ef9d98c090
commit 942c67357d
3 changed files with 3245 additions and 274 deletions

View File

@@ -4,12 +4,14 @@ import path from 'path';
import pkgs from './package.json';
import tailwindcss from '@tailwindcss/vite';
import { tanstackRouter } from '@tanstack/router-plugin/vite'
import 'dotenv/config';
import dotenv from 'dotenv';
import { VitePWA } from 'vite-plugin-pwa';
const isDev = process.env.NODE_ENV === 'development';
const env = dotenv.config().parsed || {};
const isDev = env.NODE_ENV === 'development' || process.env.NODE_ENV === 'development';
const basename = isDev ? '/' : pkgs?.basename || '/';
let target = process.env.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,
@@ -27,7 +29,10 @@ export default defineConfig({
autoCodeSplitting: true,
}),
react(),
tailwindcss()
tailwindcss(),
VitePWA({
injectRegister: 'auto',
}),
],
resolve: {
alias: {