feat: polish

This commit is contained in:
Anatoly Antonov 2026-04-22 01:27:38 +09:00
parent 2e6177fe74
commit 4bd927bb4e
137 changed files with 6357 additions and 137560 deletions

View file

@ -1,6 +1,41 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import { defineConfig, loadEnv } from 'vite';
import { mockApiPlugin } from './mocks/vitePlugin';
export default defineConfig({
plugins: [sveltekit()]
/**
* Three dev modes are supported:
*
* 1. VITE_USE_MOCK_API=true
* serve fake data from ./mocks. No backend needed.
*
* 2. VITE_API_BASE_URL starts with '/'
* client makes same-origin requests; the dev server proxies
* VITE_API_BASE_URL to VITE_API_PROXY_TARGET (default
* http://localhost:8000). This matches production where the web
* server routes /api to Django.
*
* 3. VITE_API_BASE_URL is an absolute URL
* client talks to it directly. CORS must be enabled on that host.
* No proxy is registered.
*/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
const useMock = env.VITE_USE_MOCK_API === 'true';
const base = env.VITE_API_BASE_URL ?? '/api';
const proxyTarget = env.VITE_API_PROXY_TARGET ?? 'http://localhost:8000';
const shouldProxy = !useMock && base.startsWith('/');
return {
plugins: [sveltekit(), ...(useMock ? [mockApiPlugin()] : [])],
server: {
proxy: shouldProxy
? {
[base]: {
target: proxyTarget,
changeOrigin: true,
},
}
: undefined,
},
};
});