-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
105 lines (97 loc) · 2.82 KB
/
vite.config.js
File metadata and controls
105 lines (97 loc) · 2.82 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
import { defineConfig } from 'vite';
import { resolve } from 'path';
import * as sass from 'sass';
import sassOptions from './sassOptions.js';
import { copyFileSync, mkdirSync, readdirSync, statSync, existsSync } from 'fs';
import { join, dirname } from 'path';
import { execSync } from 'child_process'; // Added for executing the combine script
// Function to copy directory recursively
function copyDir(src, dest) {
// Check if source directory exists
if (!existsSync(src)) {
console.error(`Source directory does not exist: ${src}`);
return;
}
try {
// Create destination directory if it doesn't exist
if (!existsSync(dest)) {
mkdirSync(dest, { recursive: true });
}
// Read source directory
const entries = readdirSync(src, { withFileTypes: true });
// Copy each entry recursively
for (const entry of entries) {
const srcPath = join(src, entry.name);
const destPath = join(dest, entry.name);
if (entry.isDirectory()) {
copyDir(srcPath, destPath);
} else {
try {
copyFileSync(srcPath, destPath);
} catch (error) {
mkdirSync(dirname(destPath), { recursive: true });
copyFileSync(srcPath, destPath);
}
}
}
} catch (error) {
console.error(`Error copying directory: ${error.message}`);
}
}
export default defineConfig({
root: 'src',
base: './',
publicDir: '../public', // Correctly set the public directory relative to root
build: {
outDir: '../dist',
emptyOutDir: true,
assetsInlineLimit: 4096, // Only inline assets smaller than 4kb
minify: 'terser',
terserOptions: {
compress: {
// Remove console.logs in production build
drop_console: true,
// Keep console.error and console.warn for important messages
pure_funcs: ['console.log']
}
}
},
server: {
open: true
},
resolve: {
alias: {
'@': resolve(__dirname, './src'),
},
},
css: {
preprocessorOptions: {
scss: {
implementation: sass,
...sassOptions
},
},
},
plugins: [
// Copy assets plugin
{
name: 'copy-assets-plugin',
apply: 'build',
enforce: 'post',
closeBundle: async () => {
console.log('Copying assets to build directory...');
// If you have any additional assets in src/assets, copy them too
const srcAssetsDir = resolve(__dirname, 'src/assets');
const destAssetsDir = resolve(__dirname, 'dist/assets');
if (existsSync(srcAssetsDir)) {
try {
copyDir(srcAssetsDir, destAssetsDir);
console.log('✓ Assets copied successfully from src/assets to dist/assets');
} catch (error) {
console.error(`Error copying assets: ${error.message}`);
}
}
}
}
]
})