66 lines
2.2 KiB
TypeScript
Executable File
66 lines
2.2 KiB
TypeScript
Executable File
import '../css/app.css';
|
|
import '../css/dark-mode.css';
|
|
|
|
import { createInertiaApp } from '@inertiajs/react';
|
|
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
|
|
import { createRoot } from 'react-dom/client';
|
|
import { initializeTheme } from './hooks/use-appearance';
|
|
import { initializeGlobalSettings } from './utils/globalSettings';
|
|
import { initPerformanceMonitoring, lazyLoadImages } from './utils/performance';
|
|
import './i18n'; // Import i18n configuration
|
|
import './utils/axios-config'; // Import axios configuration
|
|
import i18n from './i18n';
|
|
import { RootLayout } from './layouts/root-layout';
|
|
|
|
// Initialize performance monitoring
|
|
initPerformanceMonitoring();
|
|
|
|
// Initialize lazy loading of images when DOM is ready
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
lazyLoadImages();
|
|
});
|
|
|
|
const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
|
|
|
|
createInertiaApp({
|
|
title: (title) => (title ? `${title} - ${appName}` : appName),
|
|
resolve: (name) => {
|
|
const pages = import.meta.glob('./pages/**/*.tsx');
|
|
return resolvePageComponent(`./pages/${name}.tsx`, pages).then((module: any) => {
|
|
const page = module.default;
|
|
const oldLayout = page.layout;
|
|
|
|
// Wrap every page in RootLayout to ensure global providers stay mounted
|
|
page.layout = (children: any) => {
|
|
const content = oldLayout ? oldLayout(children) : children;
|
|
return <RootLayout>{content}</RootLayout>;
|
|
};
|
|
|
|
return module;
|
|
});
|
|
},
|
|
setup({ el, App, props }) {
|
|
// Initialize global settings
|
|
const initialGlobalSettings = props.initialPage.props.globalSettings || {};
|
|
initializeGlobalSettings(initialGlobalSettings);
|
|
|
|
// Sync global page data for utilities
|
|
try { (window as any).page = props.initialPage; } catch (e) {}
|
|
|
|
const root = createRoot(el);
|
|
|
|
initializeTheme();
|
|
|
|
const render = () => root.render(<App {...props} />);
|
|
|
|
if (i18n.isInitialized) {
|
|
render();
|
|
} else {
|
|
i18n.on('initialized', render);
|
|
}
|
|
},
|
|
progress: {
|
|
color: '#4B5563',
|
|
},
|
|
});
|