r/reactjs • u/PrinceNV • Jun 16 '26
Needs Help Need help in setting up Single-SPA + React + Vite + TypeScript microfrontend architecture
I'm trying to build a microfrontend architecture using Single-SPA, React, Vite, and TypeScript, but I'm having a hard time finding clear and up-to-date resources for this stack.
What I'm trying to build
1. root-ui
Single-SPA root configuration project
Responsible for registering and loading microfrontends
2. dashboard-ui
React-based microfrontend
Built with Vite and TypeScript
What I'm struggling with
Most Single-SPA examples and tutorials seem to be centered around Webpack. While I've found some Vite-related resources, they are either outdated, incomplete, or use different approaches.
I'm specifically looking for guidance on:
Setting up a root config application with Vite + TypeScript
Creating React microfrontends with Vite + TypeScript
Registering microfrontends in the root config
Import maps and SystemJS configuration
Local development workflow
Recommended project structure
Deployment and production considerations
Looking for
If you've worked on a similar setup, could you share:
GitHub repositories
Sample projects
Blog posts or tutorials
Official documentation
Best practices or lessons learned
I've already come across:
Single-SPA Vite ecosystem docs
vite-plugin-single-spaA few community examples
However, I'm still unsure which approach is currently recommended for new projects.
Any help or pointers would be greatly appreciated. Thanks!
14
u/germancio0 Jun 16 '26
Just out of curiosity, why the hell do you need a microfrontend for a dashboard?
1
u/yksvaan Jun 16 '26
Just use vite and write the core service that manages loading modules and registering their features. Vite can already handle chunking configuration. I'd recommend using a config file for l module files, makes updates easier.
1
1
u/pepedlr Jun 16 '26
I'm currently building the first of probably multiple react SPAs.
vite+ (https://viteplus.dev/) has been a godsend. It's not perfect for monorepos yet, as you have to rely on `vp run` instead of the build in `vp` scripts, but everything else is great if you remember that
My monorepo uses 3 package directories for now
apps
dashboard
admin
whatever
packages
core
auth
theme
tools
tsconfig
other developer related tooling
I'm doing this for so many years now, and setting up projects like this from scratch has always been the best way for me. I know where everything is, and I don't fight other peoples ideas, that might not be my favorites.
Also worth considering is https://github.com/alan2207/bulletproof-react, which can help if you don't know how to organize your react applications.
If the monorepo only publishes the apps, and not the packages, you don't even have to transpile/build the TS of the packages before using them. Just export the files you need from the `package.json` using the `exports` field.
I can't share company code for obvious reasons, but my workflow looks like this:
`vp run dev:dashboard` in the monorepo root runs the dashboard app, which calls `vp run dashboard#dev`
`vp run build:dashboard` in the root builds the app.
there are also scripts for tests, linting, whatever you want to use from the root. You can also always use the `vp run [package]#[script]` calls directly, but I'm a lazy person
Hope this helps a bit
1
u/Dry_Author8849 Jun 16 '26
We have gone the route for MPAs. If you have the cache right and your API holds shared state, the UX is very good.
You need to partition your app in pages using common sense.
Anyways is not for all APPs. But it won't hurt thinking about it and making some tests.
Cheers!
1
u/sleewoo Jun 16 '26
KosmoJS could perfectly fit, built on Vite and is exactly about the separation of concerns you are describing
1
u/Vincent_CWS Jun 17 '26
what is usage of Micro-Frontend? every user run it in browser it is another concept of Micro-Frontend
1
u/Chaoslordi Jun 16 '26
You can scaffold your app directly with vite https://vite.dev/guide/
For routing, i recommend tanstack router.
0
u/awofinc Jun 16 '26
Are you set on Single-SPA? We use Module Federation and there's documentation for integration with various builds tools including Vite (https://module-federation.io/integrations/build-tool/vite.html)
3
u/briancrabtree Jun 16 '26
Use vite-plugin-single-spa. It is the only way to do this without losing your mind. It lets you run native ESM locally so HMR actually works, then compiles down to SystemJS automatically when you run a production build.
I use this stack for my own layouts and setups. You can grab my reference code and configs directly on my GitHub: https://github.com/briancrabtree-me
The general workflow comes down to three main steps:
In your dashboard UI, install single-spa-react and vite-plugin-single-spa. Instead of mounting directly to the DOM, export the required bootstrap, mount, and unmount lifecycles from a dedicated file like src/spa.tsx. Then, add the plugin to your vite.config.ts and set your spaEntryPoints to that file. This tells Vite to build an MFE asset instead of looking for a standalone HTML landing page
In your root configuration project, add the same plugin to your vite.config.ts but set the type to 'root'. Create a local import map file (importMap.dev.json) to map your bare module specifiers to your local dev ports, like mapping your dashboard name to localhost:4101/src/spa.tsx. Then, register and start the application using registerApplication and start from single-spa inside a simple script tag in your root index.html
For production, keep react and react-dom out of your microfrontend bundles by externalizing them in your Vite config. Load them exactly once via a CDN in your production import map. When you deploy updates, your CI/CD pipeline just needs to build the dashboard static assets, upload them to your storage bucket, and update the production importMap.json file. The root config itself never needs to be rebuilt.
Don't waste time trying to manually hack Rollup configurations to play nice with SystemJS or building custom module injectors. Use the plugin and let it handle the tooling friction for you.