Repository navigation
Expand file tree
/
Copy pathvite.config.js
More file actions
90 lines (78 loc) · 2.97 KB
/
Copy pathvite.config.js
File metadata and controls
90 lines (78 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'
import path from 'path'
import fs from 'fs'
// ─── Konfiguracja ─────────────────────────────────────────────────────────────
// Zmień jeśli Vite działa na innym porcie lub hoście
const VITE_HOST = 'localhost'
const VITE_PORT = 5173
const VITE_ORIGIN = `http://${VITE_HOST}:${VITE_PORT}`
export default defineConfig(({ command }) => {
return {
plugins: [
tailwindcss(),
// Zapisuje plik .vite-dev — PHP sprawdza jego istnienie
{
name: 'wp-dev-marker',
configureServer(server) {
const marker = path.resolve(__dirname, '.vite-dev')
fs.writeFileSync(marker, VITE_ORIGIN)
server.httpServer?.on('close', () => {
try { fs.unlinkSync(marker) } catch {}
})
process.on('exit', () => {
try { fs.unlinkSync(marker) } catch {}
})
},
},
],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
// ─── Dev server ───────────────────────────────────────────────────────────
server: {
host: VITE_HOST,
port: VITE_PORT,
strictPort: true,
// KLUCZOWE: Powoduje że Vite generuje absolutne URLe w CSS/assets
// Bez tego: przeglądarka szuka assetów na domenie WP zamiast localhost:5173
origin: VITE_ORIGIN,
// CORS: true = dopuszcza wszystkie originy (WordPress na dowolnej domenie)
cors: true,
// HMR przez WebSocket
hmr: {
host: VITE_HOST,
port: VITE_PORT,
protocol: 'ws',
},
},
// ─── Production build ─────────────────────────────────────────────────────
build: {
outDir: 'dist',
emptyOutDir: true,
manifest: true,
rollupOptions: {
input: {
app: 'src/js/app.js',
woocommerce: 'src/js/woocommerce.js',
editor: 'src/css/editor.css',
},
output: {
entryFileNames: 'js/[name]-[hash].js',
chunkFileNames: 'js/chunks/[name]-[hash].js',
assetFileNames: (info) => {
const name = info.name ?? ''
if (name.endsWith('.css')) return 'css/[name]-[hash][extname]'
if (/\.(png|jpe?g|svg|gif|webp|ico)$/.test(name)) return 'images/[name]-[hash][extname]'
if (/\.(woff2?|eot|ttf|otf)$/.test(name)) return 'fonts/[name]-[hash][extname]'
return 'assets/[name]-[hash][extname]'
},
},
},
target: ['es2020', 'chrome90', 'firefox88', 'safari14'],
chunkSizeWarningLimit: 500,
},
}
})