-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathvite.config.ts
More file actions
97 lines (91 loc) · 2.35 KB
/
vite.config.ts
File metadata and controls
97 lines (91 loc) · 2.35 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
91
92
93
94
95
96
97
import { defineConfig, ViteDevServer } from 'vite';
import { execSync } from 'child_process';
import { watch } from 'fs';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
import legacy from '@vitejs/plugin-legacy';
import { VitePWA } from 'vite-plugin-pwa';
import { viteStaticCopy } from 'vite-plugin-static-copy';
const __dirname = dirname(fileURLToPath(import.meta.url));
// Custom plugin to regenerate SVG sprite when svg/ files change
function svgSpritePlugin() {
const svgDir = resolve(__dirname, 'svg');
function buildSprite() {
try {
execSync('node scripts/build-svg-sprite.js', { stdio: 'inherit' });
} catch (e) {
console.error('Failed to build SVG sprite:', e);
}
}
return {
name: 'svg-sprite',
buildStart() {
// Rebuild sprite at start of each build
buildSprite();
},
configureServer(server: ViteDevServer) {
// Watch svg/ directory and rebuild on changes
const watcher = watch(svgDir, { recursive: true }, (event, filename) => {
if (filename?.endsWith('.svg')) {
console.log(`SVG changed: ${filename}, rebuilding sprite...`);
buildSprite();
}
});
server.httpServer?.on('close', () => watcher.close());
},
};
}
export default defineConfig({
root: '.',
base: '/app/',
publicDir: 'public',
server: {
port: 3000,
},
build: {
outDir: 'dist',
sourcemap: true,
},
plugins: [
svgSpritePlugin(),
legacy({
targets: ['defaults', 'not IE 11'],
}),
viteStaticCopy({
targets: [
{
src: 'maps',
dest: '.',
},
],
}),
VitePWA({
registerType: 'prompt',
workbox: {
globPatterns: ['**/*.{js,css,html,svg,png,woff2,ico}'],
},
manifest: {
name: 'Trizbort.io',
short_name: 'Trizbort',
start_url: '.',
display: 'standalone',
theme_color: '#353537',
background_color: '#353537',
icons: [
{
src: 'web-app-manifest-192x192.png',
sizes: '192x192',
type: 'image/png',
purpose: 'maskable',
},
{
src: 'web-app-manifest-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable',
},
],
},
}),
],
});