2025-08-12 08:39:06 +00:00
|
|
|
|
import { defineConfig, loadEnv } from 'vite'
|
2025-05-06 06:45:49 +00:00
|
|
|
|
import react from '@vitejs/plugin-react'
|
|
|
|
|
|
import path from 'path'
|
|
|
|
|
|
import { VitePWA } from 'vite-plugin-pwa'
|
2025-08-13 20:42:18 +00:00
|
|
|
|
// import { fetchTenantNames } from './src/services/tenants'
|
2025-05-06 06:45:49 +00:00
|
|
|
|
|
2025-08-12 08:39:06 +00:00
|
|
|
|
export default defineConfig(async ({ mode }) => {
|
|
|
|
|
|
const env = loadEnv(mode, process.cwd(), '')
|
|
|
|
|
|
const apiUrl = env.VITE_API_URL
|
2025-08-14 08:49:22 +00:00
|
|
|
|
const baseDomains = ['sozsoft.com', 'dev.sozsoft.com', '.sozsoft.com']
|
2025-08-12 12:53:51 +00:00
|
|
|
|
|
2025-08-13 20:42:18 +00:00
|
|
|
|
// const tenantNames = (await fetchTenantNames(apiUrl)).map((n) => n.trim().toLowerCase())
|
|
|
|
|
|
// const tenantHosts = tenantNames.map((t) => `${t}.sozsoft.com`)
|
|
|
|
|
|
const tenantHosts: string[] = []
|
|
|
|
|
|
|
|
|
|
|
|
const allowedHosts = Array.from(new Set(['localhost', ...baseDomains, ...tenantHosts]))
|
2025-08-16 12:22:36 +00:00
|
|
|
|
console.log('> [vite] allowedHosts:', allowedHosts)
|
2025-08-12 12:53:51 +00:00
|
|
|
|
|
2025-08-11 22:08:28 +00:00
|
|
|
|
return {
|
|
|
|
|
|
plugins: [
|
2025-08-16 12:22:36 +00:00
|
|
|
|
react(),
|
2025-09-22 21:48:05 +00:00
|
|
|
|
VitePWA({
|
|
|
|
|
|
// Deploy'dan sonra otomatik güncelle
|
|
|
|
|
|
registerType: 'autoUpdate',
|
|
|
|
|
|
// Kayıt kodunu otomatik enjekte et (virtual:pwa-register yazmadan da çalışır)
|
|
|
|
|
|
injectRegister: 'auto',
|
|
|
|
|
|
// Dev ortamında SW'yi aç, prod'da kapalı tut (build edilmiş SW prod'da zaten aktif olur)
|
|
|
|
|
|
devOptions: {
|
|
|
|
|
|
enabled: mode !== 'production',
|
|
|
|
|
|
type: 'module', // Modern module worker kullan
|
|
|
|
|
|
},
|
2025-08-13 20:42:18 +00:00
|
|
|
|
|
2025-09-22 21:48:05 +00:00
|
|
|
|
workbox: {
|
|
|
|
|
|
// Büyük asset'leri de cache'leyebil
|
|
|
|
|
|
maximumFileSizeToCacheInBytes: 10 * 1024 * 1024,
|
2025-09-19 20:36:10 +00:00
|
|
|
|
|
2025-09-22 21:48:05 +00:00
|
|
|
|
// EN KRİTİK: yeni SW beklemeden kontrolü alsın
|
|
|
|
|
|
clientsClaim: true,
|
|
|
|
|
|
skipWaiting: true,
|
2025-09-19 20:36:10 +00:00
|
|
|
|
|
2025-09-22 21:48:05 +00:00
|
|
|
|
// Eski workbox cache'lerini temizle
|
|
|
|
|
|
cleanupOutdatedCaches: true,
|
2025-09-19 20:36:10 +00:00
|
|
|
|
|
2025-09-22 21:48:05 +00:00
|
|
|
|
// SPA fallback'i API çağrılarına uygulama
|
|
|
|
|
|
navigateFallbackDenylist: [/^\/api\//],
|
2025-09-19 20:36:10 +00:00
|
|
|
|
|
2025-09-22 21:48:05 +00:00
|
|
|
|
// ⭐⭐ BU KISMI EKLEYİN: Cache sorununu çözecek runtime caching
|
|
|
|
|
|
runtimeCaching:
|
|
|
|
|
|
mode === 'production'
|
|
|
|
|
|
? [
|
|
|
|
|
|
{
|
2025-09-23 10:45:12 +00:00
|
|
|
|
urlPattern: /\.(?:js|css|json)$/,
|
2025-09-22 21:48:05 +00:00
|
|
|
|
handler: 'NetworkFirst',
|
|
|
|
|
|
options: {
|
2025-09-24 18:18:56 +00:00
|
|
|
|
cacheName: 'static-resources-v1',
|
|
|
|
|
|
networkTimeoutSeconds: 10,
|
2025-09-22 21:48:05 +00:00
|
|
|
|
expiration: {
|
|
|
|
|
|
maxEntries: 50,
|
|
|
|
|
|
maxAgeSeconds: 24 * 60 * 60, // 24 saat
|
|
|
|
|
|
},
|
|
|
|
|
|
cacheableResponse: {
|
|
|
|
|
|
statuses: [0, 200],
|
2025-09-19 20:36:10 +00:00
|
|
|
|
},
|
2025-09-22 21:48:05 +00:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
urlPattern: /\.(?:png|jpg|jpeg|svg|gif|webp|ico)$/,
|
|
|
|
|
|
handler: 'CacheFirst',
|
|
|
|
|
|
options: {
|
|
|
|
|
|
cacheName: 'images',
|
|
|
|
|
|
expiration: {
|
|
|
|
|
|
maxEntries: 100,
|
|
|
|
|
|
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 gün
|
2025-09-19 20:36:10 +00:00
|
|
|
|
},
|
2025-09-22 21:48:05 +00:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
]
|
|
|
|
|
|
: [],
|
2025-09-19 20:36:10 +00:00
|
|
|
|
|
2025-09-22 21:48:05 +00:00
|
|
|
|
// ⭐ YENİ EKLENEN: Additional navigation route for SPA
|
|
|
|
|
|
navigateFallback: '/index.html',
|
|
|
|
|
|
navigateFallbackAllowlist: [/^(?!\/__).*/],
|
|
|
|
|
|
},
|
2025-09-19 20:36:10 +00:00
|
|
|
|
|
2025-09-22 21:48:05 +00:00
|
|
|
|
manifest: {
|
|
|
|
|
|
name: 'Sözsoft Kurs Platform',
|
|
|
|
|
|
short_name: 'Sözsoft Kurs Platform',
|
|
|
|
|
|
theme_color: '#FF99C8',
|
|
|
|
|
|
background_color: '#f0e7db',
|
|
|
|
|
|
display: 'standalone',
|
|
|
|
|
|
icons: [
|
|
|
|
|
|
{
|
|
|
|
|
|
src: '/img/logo/logo-400.png',
|
|
|
|
|
|
sizes: '400x400',
|
|
|
|
|
|
type: 'image/png',
|
|
|
|
|
|
purpose: 'any maskable',
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
src: '/img/logo/logo-192.png',
|
|
|
|
|
|
sizes: '192x192',
|
|
|
|
|
|
type: 'image/png',
|
|
|
|
|
|
purpose: 'any maskable',
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
src: '/img/logo/logo-512.png',
|
|
|
|
|
|
sizes: '512x512',
|
|
|
|
|
|
type: 'image/png',
|
|
|
|
|
|
purpose: 'any maskable',
|
2025-08-11 22:08:28 +00:00
|
|
|
|
},
|
2025-09-22 21:48:05 +00:00
|
|
|
|
],
|
|
|
|
|
|
categories: ['business', 'productivity'],
|
|
|
|
|
|
description: 'Sözsoft Kurs Platform Application',
|
|
|
|
|
|
},
|
|
|
|
|
|
}),
|
2025-08-11 22:08:28 +00:00
|
|
|
|
],
|
2025-08-13 20:42:18 +00:00
|
|
|
|
|
2025-08-11 22:08:28 +00:00
|
|
|
|
server: {
|
|
|
|
|
|
open: true,
|
|
|
|
|
|
port: 3000,
|
2025-09-13 11:46:34 +00:00
|
|
|
|
// ⭐ YENİ EKLENEN: Hot reload için polling
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
usePolling: true,
|
2025-09-19 20:36:10 +00:00
|
|
|
|
interval: 1000,
|
|
|
|
|
|
},
|
2025-08-11 22:08:28 +00:00
|
|
|
|
},
|
2025-08-13 20:42:18 +00:00
|
|
|
|
|
2025-08-11 22:08:28 +00:00
|
|
|
|
assetsInclude: ['**/*.md'],
|
2025-08-13 20:42:18 +00:00
|
|
|
|
|
2025-08-11 22:08:28 +00:00
|
|
|
|
resolve: {
|
|
|
|
|
|
alias: {
|
|
|
|
|
|
'@': path.join(__dirname, 'src'),
|
|
|
|
|
|
inferno: 'inferno/dist/index.esm.js',
|
|
|
|
|
|
'devextreme/ui': 'devextreme/esm/ui',
|
2025-05-06 06:45:49 +00:00
|
|
|
|
},
|
|
|
|
|
|
},
|
2025-08-13 20:42:18 +00:00
|
|
|
|
|
2025-08-11 22:08:28 +00:00
|
|
|
|
build: {
|
|
|
|
|
|
outDir: 'dist',
|
|
|
|
|
|
sourcemap: false,
|
2025-09-19 20:36:10 +00:00
|
|
|
|
emptyOutDir: true,
|
|
|
|
|
|
rollupOptions: {
|
|
|
|
|
|
output: {
|
2025-09-24 18:18:56 +00:00
|
|
|
|
entryFileNames: `assets/js/[name]-[hash].js`,
|
|
|
|
|
|
chunkFileNames: `assets/js/[name]-[hash].js`,
|
|
|
|
|
|
assetFileNames: ({ name }) => {
|
|
|
|
|
|
if (/\.(css)$/.test(name ?? '')) {
|
|
|
|
|
|
return 'assets/css/[name]-[hash][extname]'
|
|
|
|
|
|
}
|
|
|
|
|
|
if (/\.(png|jpe?g|svg|gif|ico|webp)$/.test(name ?? '')) {
|
|
|
|
|
|
return 'assets/img/[name]-[hash][extname]'
|
|
|
|
|
|
}
|
|
|
|
|
|
return 'assets/[name]-[hash][extname]'
|
|
|
|
|
|
},
|
2025-09-19 20:36:10 +00:00
|
|
|
|
},
|
|
|
|
|
|
},
|
2025-08-11 22:08:28 +00:00
|
|
|
|
},
|
2025-08-13 20:42:18 +00:00
|
|
|
|
|
2025-08-11 22:08:28 +00:00
|
|
|
|
preview: {
|
|
|
|
|
|
host: '0.0.0.0',
|
|
|
|
|
|
port: 80,
|
|
|
|
|
|
open: false,
|
2025-08-13 20:42:18 +00:00
|
|
|
|
// Hesaplanan allowedHosts'u kullan
|
|
|
|
|
|
allowedHosts,
|
2025-08-11 22:08:28 +00:00
|
|
|
|
},
|
2025-08-13 20:42:18 +00:00
|
|
|
|
|
2025-08-11 22:08:28 +00:00
|
|
|
|
define: {
|
|
|
|
|
|
'process.env': {},
|
2025-09-13 11:46:34 +00:00
|
|
|
|
// ⭐ YENİ EKLENEN: Version tracking için global değişkenler
|
2025-09-19 20:36:10 +00:00
|
|
|
|
__APP_VERSION__: JSON.stringify(process.env.VITE_APP_VERSION || '1.0.0'),
|
2025-09-13 11:46:34 +00:00
|
|
|
|
__BUILD_DATE__: JSON.stringify(new Date().toISOString()),
|
2025-09-19 20:36:10 +00:00
|
|
|
|
__APP_MODE__: JSON.stringify(mode),
|
2025-08-11 22:08:28 +00:00
|
|
|
|
},
|
|
|
|
|
|
}
|
2025-09-19 20:36:10 +00:00
|
|
|
|
})
|