-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
64 lines (59 loc) · 1.56 KB
/
vite.config.ts
File metadata and controls
64 lines (59 loc) · 1.56 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
/**
* Vite configuration file for the Happy Moments Companion app.
*
* This file configures the Vite build tool for a React application using TypeScript.
* It uses the @vitejs/plugin-react and vite packages.
*/
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { fileURLToPath, URL } from 'node:url';
import * as fs from 'node:fs';
// Validate VITE_API_URL
function isValidURL(str: string): boolean {
try {
new URL(str);
return true;
} catch (_) {
return false;
}
}
// Environment variables
const VITE_APP_TITLE = process.env.VITE_APP_TITLE || 'Happy Moments Companion';
const VITE_API_URL = process.env.VITE_API_URL || 'http://localhost:3000';
const VITE_THREE_MODEL_PATH = process.env.VITE_THREE_MODEL_PATH || '/models/';
if (!isValidURL(VITE_API_URL)) {
throw new Error('VITE_API_URL is not a valid URL.');
}
// https://vitejs.dev/config/
export default defineConfig({
base: '/',
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
esbuild: {
jsxInject: `import React from 'react'`,
},
plugins: [react()],
define: {
'process.env': {
VITE_APP_TITLE: JSON.stringify(VITE_APP_TITLE),
VITE_API_URL: JSON.stringify(VITE_API_URL),
VITE_THREE_MODEL_PATH: JSON.stringify(VITE_THREE_MODEL_PATH),
},
},
build: {
sourcemap: true,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('src/components')) {
return 'components';
}
return 'vendor';
},
},
},
},
});