How do I pre-render my react app created by Vite?

774 Views Asked by At

I am trying to prerender my vite react app with the react-snap package.

I have tried the procedure of prerendering with the following code. But it doesn't get build in production (I configured GitHub action for deployment).

const Main = (
    <React.StrictMode>
        <BrowserRouter>
            <Suspense fallback={<Loader />}>
                <Provider store={store}>
                    <App />
                </Provider>
            </Suspense>
        </BrowserRouter>
    </React.StrictMode>
);

const rootElement = document.getElementById("root");

if (rootElement.hasChildNodes()) {
    ReactDOM.createRoot(rootElement).hydrate(Main);
} else {
    ReactDOM.createRoot(rootElement).render(Main);
}

Probably I have to change someting in my vite.config.js file.

Any kind of help would be really appriciated.

0

There are 0 best solutions below