@grasp-labs/ds-microfrontends-integration 0.24.0 → 0.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -30
- package/dist/{index-8Q3EeCug.js → index-DWI6fl0D.js} +1285 -1274
- package/dist/{index.esm-fQDYRCEr-Bj1dI6i0.js → index.esm-fQDYRCEr-B_OscmDH.js} +1 -1
- package/dist/index.js +28 -26
- package/dist/mf-common.d.ts +1 -30
- package/dist/mf-common.js +22 -22
- package/dist/types/Navigation.d.ts +47 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/navigation.d.ts +23 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -106,9 +106,48 @@ import "@grasp-labs/ds-microfrontends-integration/styles.css";
|
|
|
106
106
|
|
|
107
107
|
### Microfrontend Configuration (`/mf-common`)
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
The platform uses a **host / remote** architecture powered by [Module Federation](https://module-federation.io/). A central host application dynamically discovers and mounts independent microfrontend remotes at runtime. For this to work, every remote must follow a shared contract — exposing the same entry points, using compatible shared dependencies, and providing a navigation config so the host can build its sidebar and routing.
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
`mf-common` enforces this contract. It provides a pre-configured Vite plugin, shared dependency definitions, and type-safe navigation primitives so that each remote is wired up correctly with minimal boilerplate.
|
|
112
|
+
|
|
113
|
+
#### The Contract
|
|
114
|
+
|
|
115
|
+
Every microfrontend must expose two modules:
|
|
116
|
+
|
|
117
|
+
| Expose key | Default path | What the host expects |
|
|
118
|
+
| ---------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
119
|
+
| `"."` | `"./src/App"` | A **React component** (not a full app with `ReactDOM.render`). The host mounts it inside its own router |
|
|
120
|
+
| `"./navigationConfig"` | `"./src/navigationConfig"` | A `ComposableNavigationConfig` object. The host reads it to build sidebar entries and route definitions |
|
|
121
|
+
|
|
122
|
+
#### Navigation Item Types
|
|
123
|
+
|
|
124
|
+
Each entry in the navigation config is a `NavigationItem` — either a **route** or a **category**:
|
|
125
|
+
|
|
126
|
+
| Type | Description |
|
|
127
|
+
| ---------- | -------------------------------------------------------------------------- |
|
|
128
|
+
| `visible` | A route that appears in the sidebar (default when `type` is omitted) |
|
|
129
|
+
| `hidden` | A route that is routable but does not appear in the sidebar |
|
|
130
|
+
| `category` | A non-routable group with `children` — used to create nested sidebar menus |
|
|
131
|
+
|
|
132
|
+
Every item has a `label` (display fallback), an optional `labelKey` (i18n key in the `navigation` namespace), and an `icon`.
|
|
133
|
+
|
|
134
|
+
#### Available Utilities
|
|
135
|
+
|
|
136
|
+
**Build-time** (`@grasp-labs/ds-microfrontends-integration/mf-common`):
|
|
137
|
+
|
|
138
|
+
- `dsFederation(name, overrides?)` — Vite plugin that wraps Module Federation with the standard config
|
|
139
|
+
- `createModuleFederationConfig(name, overrides?)` — generates the raw Module Federation options if you need more control
|
|
140
|
+
- `createMicrofrontendsBase(name)` — returns the deployment base path (`microfrontends/<name>/`), used to set Vite's `base` in production
|
|
141
|
+
- `COMMON_SHARED_DEPS` — shared dependency definitions (React, React Router, this package) configured as singletons
|
|
142
|
+
- Types: `MicrofrontendExposes`
|
|
143
|
+
|
|
144
|
+
**Client-side** (`@grasp-labs/ds-microfrontends-integration`):
|
|
145
|
+
|
|
146
|
+
- `defineNavigation(config)` — defines a navigation config and extracts its page routes in one step, returning `{ navigationConfig, pageRoutes }`
|
|
147
|
+
- `extractPaths(config)` — recursively flattens a navigation config into a type-safe `{ KEY: path }` map
|
|
148
|
+
- Types: `RouteConfig`, `CategoryConfig`, `NavigationItem`, `ComposableNavigationConfig`
|
|
149
|
+
|
|
150
|
+
#### Vite Setup
|
|
112
151
|
|
|
113
152
|
```typescript
|
|
114
153
|
// vite.config.ts
|
|
@@ -128,14 +167,9 @@ export default defineConfig(({ mode }) => ({
|
|
|
128
167
|
}));
|
|
129
168
|
```
|
|
130
169
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
- `"."` → `"./src/App"` - Your main React component (not a full app with ReactDOM.render, just a component)
|
|
134
|
-
- `"./navigationConfig"` → `"./src/navigationConfig"` - Navigation configuration object of type `NavigationConfig`
|
|
135
|
-
|
|
136
|
-
#### App Component Example
|
|
170
|
+
#### App Component
|
|
137
171
|
|
|
138
|
-
Your `src/App.tsx` should export a React component with Routes
|
|
172
|
+
Your `src/App.tsx` should export a React component with `<Routes>`, not render it — the host handles mounting:
|
|
139
173
|
|
|
140
174
|
```tsx
|
|
141
175
|
// src/App.tsx
|
|
@@ -157,14 +191,16 @@ function App() {
|
|
|
157
191
|
export default App;
|
|
158
192
|
```
|
|
159
193
|
|
|
160
|
-
#### Navigation Configuration
|
|
194
|
+
#### Navigation Configuration
|
|
195
|
+
|
|
196
|
+
Use `defineNavigation` to define your navigation config and extract route paths in one step:
|
|
161
197
|
|
|
162
198
|
```typescript
|
|
163
199
|
// src/navigationConfig.ts
|
|
164
|
-
import
|
|
200
|
+
import { defineNavigation } from "@grasp-labs/ds-microfrontends-integration";
|
|
165
201
|
|
|
166
|
-
|
|
167
|
-
|
|
202
|
+
const { navigationConfig, pageRoutes: PageRoutes } = defineNavigation({
|
|
203
|
+
HOME: {
|
|
168
204
|
label: "Home",
|
|
169
205
|
path: "/",
|
|
170
206
|
icon: "database",
|
|
@@ -181,21 +217,17 @@ export const navigationConfig = {
|
|
|
181
217
|
path: "/internal",
|
|
182
218
|
type: "hidden",
|
|
183
219
|
},
|
|
184
|
-
}
|
|
185
|
-
```
|
|
220
|
+
});
|
|
186
221
|
|
|
187
|
-
|
|
222
|
+
export { PageRoutes };
|
|
223
|
+
// PageRoutes.HOME === "/"
|
|
224
|
+
// PageRoutes.SETTINGS === "/settings"
|
|
225
|
+
// PageRoutes.INTERNAL === "/internal"
|
|
188
226
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
- Type-safe navigation and route configuration helpers
|
|
192
|
-
|
|
193
|
-
**Available utilities:**
|
|
227
|
+
export default navigationConfig;
|
|
228
|
+
```
|
|
194
229
|
|
|
195
|
-
|
|
196
|
-
- `createModuleFederationConfig(name, overrides?)` - Generate config object
|
|
197
|
-
- `COMMON_SHARED_DEPS` - Shared dependency configuration
|
|
198
|
-
- Types: `RouteConfig`, `NavigationConfig`, `MicrofrontendExposes`
|
|
230
|
+
For nested configs with categories, route paths are recursively flattened into a single map.
|
|
199
231
|
|
|
200
232
|
#### Shared Dependencies
|
|
201
233
|
|
|
@@ -203,10 +235,10 @@ Your microfrontend project must install compatible versions of these shared depe
|
|
|
203
235
|
|
|
204
236
|
| Dependency | Purpose |
|
|
205
237
|
| ------------------------------------------- | ------------------------------------------------------------------------------------ |
|
|
206
|
-
| `react` | UI library
|
|
207
|
-
| `react-dom` | React DOM renderer
|
|
208
|
-
| `react-router` | Routing library
|
|
209
|
-
| `@grasp-labs/ds-microfrontends-integration` | This package
|
|
238
|
+
| `react` | UI library — singleton ensures one React instance across all microfrontends |
|
|
239
|
+
| `react-dom` | React DOM renderer — must match React version |
|
|
240
|
+
| `react-router` | Routing library — singleton required for React context to work across microfrontends |
|
|
241
|
+
| `@grasp-labs/ds-microfrontends-integration` | This package — singleton required for React context to work across microfrontends |
|
|
210
242
|
|
|
211
243
|
These dependencies are configured as singletons to prevent multiple instances and ensure compatibility across the microfrontend architecture.
|
|
212
244
|
|
|
@@ -267,7 +299,7 @@ src/
|
|
|
267
299
|
├── lib/ # JSON schema utilities and shared logic
|
|
268
300
|
├── types/ # TypeScript type definitions
|
|
269
301
|
├── utils/ # Shared helper functions
|
|
270
|
-
├── mf-common.ts #
|
|
302
|
+
├── mf-common.ts # Build-time microfrontend configuration (Vite plugin, Module Federation)
|
|
271
303
|
└── index.ts # Main entry point
|
|
272
304
|
```
|
|
273
305
|
|