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", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"copy-yaml": "mkdir -p public/data/database && cp src/assets/database/*.yaml public/data/database/", "build": "tsc -b && vite build",
"build": "npm run copy-yaml && tsc -b && vite build",
"lint": "eslint .", "lint": "eslint .",
"preview": "vite preview" "preview": "vite preview"
}, },

View File

@@ -12,7 +12,7 @@ function App() {
useEffect(() => { useEffect(() => {
const loadData = async () => { const loadData = async () => {
try { try {
const response = await fetch('/data/Faelyn Eichenhauch.json'); const response = await fetch('/data/Faelyn Eichenahauch.json');
if (!response.ok) { if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`); 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[]> { async function loadData<T>(fileName: string): Promise<T[]> {
try { try {
const response = await fetch(`/data/database/${fileName}`); // Ensure proper file extension
if (!response.ok) { const fileNameWithExt = fileName.endsWith('.json') ? fileName : `${fileName}.json`;
throw new Error(`Failed to load ${fileName}: ${response.statusText}`); 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) { } catch (error) {
console.error(`Error loading ${fileName}:`, error); console.error(`Error loading ${fileName}:`, error);
throw error; throw error;

View File

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