You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following example, we demonstrate how to define and export an array of providers that include both Provider and EnvironmentProviders. This array can be used with ngx-fastboot to dynamically load and resolve these providers during application bootstrap, optimizing the initial load performance.
95
+
`ngx-fastboot` provides great flexibility in how providers are loaded. Each element of the `providers` field can be either a **single provider** or an **array of providers**, depending on the needs of your application.
96
96
97
+
You can specify these providers in three main ways:
98
+
99
+
-**Static import**: The traditional method used during the application's bootstrap, where providers are imported and directly included at configuration time. This approach is simple but can increase the initial bundle size.
100
+
101
+
-**Dynamic Named Import**: To reduce the bundle size, you can load providers dynamically using a named import. In this way, providers are only loaded when they are actually needed.
102
+
103
+
-**Dynamic Default Import**: Similar to named import, but loads the provider or a group of providers using the default export of the module. This is useful when a module exports a single provider or an array of providers as a default value.
console.error('Error bootstrapping the app', error);
214
+
});
215
+
```
216
+
217
+
### RootComponent
218
+
219
+
Similar to providers, you can manage the root component of the application both **statically** and **dynamically**. Dynamically loading the root component can help reduce the initial bundle size.
220
+
221
+
#### Static Import
222
+
223
+
The classic method to bootstrap the root component involves a static import:
224
+
225
+
```typescript
226
+
fast(bootstrapApplication, AppComponent, {
227
+
providers: [...]
228
+
});
229
+
```
230
+
231
+
#### Dynamic Named Import
232
+
To optimize bundle size, the root component can be loaded dynamically with a named import:
Alternatively, you can use a dynamic default import if the root component is exported as the default from the module:
244
+
245
+
```typescript
246
+
fast(
247
+
bootstrapApplication,
248
+
() =>import('./app-component'), {
249
+
providers: [...]
250
+
});
251
+
```
252
+
109
253
### Sentry Integration Example
110
254
This example shows how to integrate Sentry with ngx-fastboot for error monitoring and performance tracing in your Angular application.
111
255
@@ -186,7 +330,7 @@ Dynamically loads the specified providers in the configuration and bootstraps an
186
330
#### Parameters
187
331
188
332
-**`bootstrap`**: The Angular application's bootstrap function (typically `bootstrapApplication`).
189
-
-**`rootComponent`**: The root component of the application, which should be of type `Type<unknown>`.
333
+
-**`rootComponent`**: The root component of the application, which should be of type `FastComponent`.
190
334
-**`options`**: (Optional) The application configuration, including the providers to be loaded. It should conform to the `FastApplicationConfig` type. Providers can be `Provider`, `EnvironmentProviders`, or lazy modules that return these providers.
191
335
192
336
#### Returns
@@ -221,6 +365,18 @@ export type LazyModule<T> = () => Promise<T | { default: T }>;
0 commit comments