-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.main.config.ts
More file actions
51 lines (47 loc) · 1.47 KB
/
Copy pathvite.main.config.ts
File metadata and controls
51 lines (47 loc) · 1.47 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
import { defineConfig } from 'vite';
import * as fs from 'fs';
import * as path from 'path';
// https://vitejs.dev/config
export default defineConfig({
publicDir: false, // We'll handle copying manually
define: {
// Define a constant that can be used to determine asset paths
__STATIC__: '""'
},
build: {
rollupOptions: {
output: {
// Handle dynamic imports properly
manualChunks: undefined
}
}
},
plugins: [
{
name: 'copy-assets',
buildStart() {
},
generateBundle() {
// Copy images directory to build output
const imagesSource = path.resolve(__dirname, 'images');
const imagesDest = path.resolve(__dirname, '.vite/images');
if (fs.existsSync(imagesSource)) {
// Create destination directory if it doesn't exist
if (!fs.existsSync(path.dirname(imagesDest))) {
fs.mkdirSync(path.dirname(imagesDest), { recursive: true });
}
if (!fs.existsSync(imagesDest)) {
fs.mkdirSync(imagesDest, { recursive: true });
}
// Copy all files from images to .vite/images
const files = fs.readdirSync(imagesSource);
files.forEach((file: string) => {
const sourceFile = path.join(imagesSource, file);
const destFile = path.join(imagesDest, file);
fs.copyFileSync(sourceFile, destFile);
});
}
}
}
]
});