Refactor database handling: switch YAML to JSON imports, update data loader, and clean build process.
This commit is contained in:
@@ -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"
|
||||
},
|
||||
|
@@ -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}`);
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user