-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathvite.config.js
More file actions
70 lines (66 loc) · 1.78 KB
/
Copy pathvite.config.js
File metadata and controls
70 lines (66 loc) · 1.78 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
import { defineConfig } from 'vite';
import { resolve } from 'path';
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import packagejson from './package.json';
const versionnumber = packagejson.version;
// Get the directory name of the current module
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Try to read .env.json file
let googleAnalytics = '';
try {
const envFile = readFileSync(resolve(__dirname, '.env.json'), 'utf8');
const envData = JSON.parse(envFile);
googleAnalytics = envData.googleanalytics || '';
} catch (error) {
// File doesn't exist or is invalid, use empty string
console.log('No .env.json file found, using empty string for googleAnalytics');
googleAnalytics = '';
}
export default defineConfig(({ command }) => ({
root: 'src',
build: {
outDir: '../dist',
emptyOutDir: true,
rolldownOptions: {
input: {
main: 'src/index.html',
about: 'src/about.html'
}
}
},
server: {
port: 3000,
open: true
},
resolve: {
alias: {
'~bootstrap': resolve(__dirname, 'node_modules/bootstrap'),
'bootstrap-icons': resolve(__dirname, 'node_modules/bootstrap-icons/font/bootstrap-icons.css'),
}
},
optimizeDeps: {
include: [
'jquery',
'bootstrap',
'bootstrap-icons',
'datatables.net',
'datatables.net-bs5',
'datatables.net-dt',
'luxon',
'clipboard'
]
},
plugins: [
{
name: 'html-transform',
transformIndexHtml(html) {
return html
.replace(/__VERSIONNUMBER__/g, versionnumber)
.replace(/<!-- Google Analytics -->/g, (command === 'build') ? googleAnalytics : '<!-- Google Analytics -->');
},
}
],
}));