-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
42 lines (34 loc) · 1.22 KB
/
vite.config.js
File metadata and controls
42 lines (34 loc) · 1.22 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
// vite.config.js
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import { readFileSync } from 'fs';
function getRepoName() {
try {
const packageJsonPath = path.resolve(__dirname, 'package.json');
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
const homepage = packageJson.homepage;
if (homepage) {
const url = new URL(homepage);
console.log('Detected homepage URL in vite.config.js:', homepage);
console.log('Extracted repository path in vite.config.js:', url.pathname);
return url.pathname;
}
} catch (error) {
console.warn('Could not read package.json or homepage in vite.config.js. Defaulting base to "/"');
console.error('Specific error during package.json read:', error);
}
console.log('Defaulting base to "/" in vite.config.js');
return '/';
}
const base = process.env.NODE_ENV === 'production'
? getRepoName()
: '/';
console.log('Final Vite base configuration for build:', base);
export default defineConfig({
plugins: [react()],
base: base,
});