How adeeshsharma/react-single-spa-widget works
Project type and purpose
• This is a front-end “micro-frontend” style project composed of two parts:
a) carousel-widget – a standalone React widget/library packaged as a UMD bundle (built with Webpack/Vite).
b) host-app – a React application (Vite-powered) that dynamically loads and mounts the UMD widget at runtime (per the linked Single-SPA approach).
File structure
• Top-level directories:
• carousel-widget/ – source (src/), styles, bundler configs (webpack.config.cjs, vite.config.js), build output (public/), entry points (index.js, index.html).
• host-app/ – application source (src/), HTML shell (index.html), build config (vite.config.js), and dynamic loader logic in App.jsx.
• Config files: ESLint in both, package.json, bundler configs.
• Patterns: separation of library vs. consumer, use of UMD module for runtime integration.
README for additional insights
• The README links to a blog detailing building a standalone React widget (UMD) and loading it into another React app using Single-SPA.
• This confirms the architecture is a micro-frontend/widget integration scenario, not a monolith.
a. Main components:
• Developer Workstations (for widget & host)
• carousel-widget Build Pipeline
– Source code (Carousel.js, CSS)
– Bundlers: Webpack &/or Vite
– Output: UMD bundle (JS), CSS
– CDN or local dev-server
• host-app Build Pipeline
– Source (App.jsx, main.jsx)
– Vite dev server / production build
– index.html shell
• Runtime Environment (Browser)
– host-app container loads its own bundle
– Dynamically injects <script> tag pointing to carousel-widget UMD
– Mount point DOM node (e.g.
)
• External dependencies
– React, ReactDOM (peer-loaded by host or bundled by widget)
b. Relationships and interactions:
1. Developers → run npm run build in carousel-widget → Bundler outputs carousel.umd.js → published/served.
2. Developers → serve or build host-app → host code references the remote UMD URL.
3. Browser loads host-app code → at mount time, host injects <script src="...carousel.umd.js"> → once loaded, calls widget’s UMD register function → widget mounts into the host’s DOM.
4. CSS styling loaded either via widget’s CSS file or inlined.
c. Architectural patterns / design principles:
• Micro-frontend / widget as a standalone module
• UMD packaging for broad compatibility
• Dynamic script injection (Single-SPA style)
• Clear separation of concerns: widget logic vs. host orchestration
• Peer dependencies (React) to avoid duplication
d. Key technologies / frameworks:
• React / ReactDOM
• Webpack (for UMD output)
• Vite (for both widget dev mode and host dev mode)
• Single-SPA dynamic loading pattern
• NPM scripts / package.json orchestrators