I am biginner in inertiajs ecosystem. Therefore, I punctually follow the documentation of the technologies in question.
In inertiajs documentation they say: “By default we recommend eager loading your components, which will result in a single JavaScript bundle. However, if you’d like to lazy-load your components”…
Then i try to apply this recommendation in the project. Adding {eager:true} to the import.meta.glob
import { createRoot } from 'react-dom/client';
import { createInertiaApp, router } from '@inertiajs/react';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import '../sass/style.scss';
const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
createInertiaApp({
title: title => `${title} - ${appName}`,
resolve: name =>
{
const page = resolvePageComponent(
`./Pages/${name}.tsx`,
import.meta.glob('./Pages/**/*.tsx', { eager: true }) // here is the change,
)
console.log(name,import.meta.glob('./Pages/**/*.tsx'),{page});
return page;
},
setup({ el, App, props }) {
const root = createRoot(el);
root.render(<App {...props} />);
},
progress: {
color: '#F87415'
}
});
// evento al iniciar request
router.on('start',(event)=>{
console.log('start',{event});
let appLoader = document.getElementById('loader');
appLoader?.classList.remove('hidden');
});
// evento al finalizar request
router.on('finish',(event)=>{
console.log('finish',{event});
let appLoader = document.getElementById('loader');
appLoader?.classList.add('hidden');
});
After that the application show me the error.
@vitejs/plugin-react can’t detect preamble. Something is wrong
With this last change the application stopped working, can someone explain to me what is wrong?
I am using laravel11, innertiajs, vitejs and react. Thanks in advance.
I try investigate following the link in the browser console but don’t found answer.
pichurr0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.