-
Notifications
You must be signed in to change notification settings - Fork 480
Expand file tree
/
Copy pathvite.config.js
More file actions
112 lines (106 loc) · 2.89 KB
/
Copy pathvite.config.js
File metadata and controls
112 lines (106 loc) · 2.89 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { defineConfig } from 'vite';
import { copyFileSync, mkdirSync, readdirSync, statSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Plugin to copy additional public files
function copyPublicFiles() {
return {
name: 'copy-public-files',
closeBundle() {
const filesToCopy = [
'about.html',
'favicon.ico',
'humans.txt',
'manifest.webapp',
'robots.txt',
'webstore-manifest.json'
];
filesToCopy.forEach(file => {
try {
const src = join(__dirname, 'app', file);
const dest = join(__dirname, 'dist', file);
copyFileSync(src, dest);
} catch (err) {
console.warn(`Failed to copy ${file}:`, err.message);
}
});
// Copy all images
const copyDir = (src, dest) => {
try {
mkdirSync(dest, { recursive: true });
const entries = readdirSync(src);
entries.forEach(entry => {
const srcPath = join(src, entry);
const destPath = join(dest, entry);
const stat = statSync(srcPath);
if (stat.isDirectory()) {
copyDir(srcPath, destPath);
} else {
copyFileSync(srcPath, destPath);
}
});
} catch (err) {
console.warn(`Failed to copy directory ${src}:`, err.message);
}
};
copyDir(join(__dirname, 'app', 'images'), join(__dirname, 'dist', 'images'));
}
};
}
export default defineConfig({
root: 'app',
build: {
outDir: '../dist',
emptyOutDir: true,
rollupOptions: {
input: {
main: './app/index.html',
sw: './app/sw.js'
},
output: {
entryFileNames: (chunkInfo) => {
// Service worker at root
if (chunkInfo.name === 'sw') {
return '[name].js';
}
// Everything else in scripts directory
return 'scripts/[name].js';
},
chunkFileNames: 'scripts/[name].js',
assetFileNames: (assetInfo) => {
// Keep styles in styles directory
if (assetInfo.name.endsWith('.css')) {
return 'styles/[name].[ext]';
}
// Keep images in images directory
if (/\.(png|jpg|jpeg|gif|svg|ico|webp)$/.test(assetInfo.name)) {
return 'images/[name].[ext]';
}
// Everything else in root or appropriate location
return '[name].[ext]';
}
}
},
target: 'es2020',
minify: 'terser'
},
plugins: [copyPublicFiles()],
worker: {
format: 'es',
rollupOptions: {
output: {
entryFileNames: 'scripts/[name].js'
}
}
},
server: {
port: 8080,
strictPort: false
},
preview: {
port: 8080,
strictPort: false
}
});