Refactor database handling: switch YAML to JSON imports, update data loader, and clean build process.

This commit is contained in:
2025-07-06 20:56:13 +02:00
parent e3fe82990d
commit 2323e9f277
65 changed files with 28 additions and 21 deletions

View File

@@ -5,8 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"copy-yaml": "mkdir -p public/data/database && cp src/assets/database/*.yaml public/data/database/",
"build": "npm run copy-yaml && tsc -b && vite build",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},

View File

@@ -12,7 +12,7 @@ function App() {
useEffect(() => {
const loadData = async () => {
try {
const response = await fetch('/data/Faelyn Eichenhauch.json');
const response = await fetch('/data/Faelyn Eichenahauch.json');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

View File

@@ -67,11 +67,19 @@ import type {Skill, Skills} from '../types/Skill';
*/
async function loadData<T>(fileName: string): Promise<T[]> {
try {
const response = await fetch(`/data/database/${fileName}`);
if (!response.ok) {
throw new Error(`Failed to load ${fileName}: ${response.statusText}`);
// Ensure proper file extension
const fileNameWithExt = fileName.endsWith('.json') ? fileName : `${fileName}.json`;
const module = await import(`../assets/database/${fileNameWithExt}`);
// Access the default export or named export
const data = module.default || module;
// Validate it's an array
if (!Array.isArray(data)) {
throw new Error(`Data from ${fileName} is not an array`);
}
return await response.json();
return data as T[];
} catch (error) {
console.error(`Error loading ${fileName}:`, error);
throw error;

View File

@@ -4,19 +4,19 @@ import tailwindcss from "@tailwindcss/vite";
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
tailwindcss(),
],
base: './',
build: {
minify: 'esbuild', // ← Statt terser
rollupOptions: {
output: {
assetFileNames: 'assets/[name].[ext]',
chunkFileNames: 'assets/[name].js',
entryFileNames: 'assets/[name].js'
}
}
plugins: [
react(),
tailwindcss(),
],
base: './',
build: {
minify: 'esbuild', // ← Statt terser
rollupOptions: {
output: {
assetFileNames: 'assets/[name].[ext]',
chunkFileNames: 'assets/[name].js',
entryFileNames: 'assets/[name].js'
}
}
}
})