-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathvite.config.ts
More file actions
51 lines (47 loc) · 1.17 KB
/
vite.config.ts
File metadata and controls
51 lines (47 loc) · 1.17 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 { readFileSync } from 'node:fs';
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
import svgr from 'vite-plugin-svgr';
import path from 'path';
import tailwindcss from '@tailwindcss/vite';
function getBaseUrl() {
const { homepage } = JSON.parse(readFileSync('package.json', 'utf-8')) as {
homepage?: string;
};
if (!homepage) return '/';
// If it's a full URL, extract just the pathname
if (homepage.startsWith('http')) {
const url = new URL(homepage);
return url.pathname === '/' ? '/' : url.pathname.replace(/\/$/, '') + '/';
}
const base = homepage.startsWith('/') ? homepage : `/${homepage}`;
return base.replace(/\/$/, '') + '/';
}
export default defineConfig({
base: getBaseUrl(),
plugins: [
react(),
svgr({
include: '**/*.svg',
svgrOptions: { exportType: 'named', namedExport: 'ReactComponent' },
}),
tailwindcss(),
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
server: {
host: '0.0.0.0',
port: 3000,
open: true,
},
build: {
outDir: 'build',
},
test: {
environment: 'jsdom',
pool: 'vmForks',
},
});