-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
71 lines (68 loc) · 1.6 KB
/
Copy pathvite.config.ts
File metadata and controls
71 lines (68 loc) · 1.6 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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { copyFileSync } from 'fs'
import { join, dirname } from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const hmrHost = 'localhost'
const hmrPort = Number(3000)
const hmrClientPort = Number(hmrPort)
const hmrProtocol = 'ws'
// https://vitejs.dev/config/
export default defineConfig({
base: '/', // Explicitly set base path
plugins: [
react({
jsxRuntime: 'automatic',
}),
{
name: 'copy-service-worker',
closeBundle() {
// Copy service worker to dist API reference need to use the smart copy codefolder
try {
copyFileSync(
join(__dirname, 'public/sw.js'),
join(__dirname, 'dist/sw.js')
)
} catch (error) {
console.warn('Failed to copy service worker:', error)
}
}
}
],
resolve: {
dedupe: ['react', 'react-dom'],
},
optimizeDeps: {
include: ['react', 'react-dom', 'react-router-dom'],
},
build: {
rollupOptions: {
output: {
entryFileNames: 'assets/[name]-[hash].js',
chunkFileNames: 'assets/[name]-[hash].js',
assetFileNames: 'assets/[name]-[hash].[ext]'
}
},
target: 'es2020',
sourcemap: false
},
server: {
port: 3000,
host: '0.0.0.0',
hmr: {
host: hmrHost,
port: hmrPort,
clientPort: hmrClientPort,
protocol: hmrProtocol
},
watch: {
usePolling: false
}
},
preview: {
port: 5173,
host: true
}
})