@@ -34,31 +34,34 @@ export function lottiePlayerFactory() {
34
34
return player ;
35
35
}
36
36
37
+ // Common imports
38
+ const imports = [
39
+ BrowserModule ,
40
+ BrowserAnimationsModule ,
41
+ IonicModule . forRoot ( ) ,
42
+ AppRoutingModule ,
43
+ HttpClientModule ,
44
+ SharedModule ,
45
+ FormsModule ,
46
+ LottieModule . forRoot ( { player : lottiePlayerFactory } ) ,
47
+ // NOTE CC 2021-11-04 not sure if cache causes issues or not https://github.com/ngx-lottie/ngx-lottie/issues/115
48
+ // LottieCacheModule.forRoot(),
49
+ TemplateComponentsModule ,
50
+ TourModule ,
51
+ MatomoModule . forRoot ( {
52
+ siteId : environment . analytics . siteId ,
53
+ trackerUrl : environment . analytics . endpoint ,
54
+ } ) ,
55
+ MatomoRouterModule ,
56
+ ContextMenuModule ,
57
+ ] ;
58
+
59
+ // Deployment-specific imports
60
+ loadFirebaseImports ( ) ;
61
+
37
62
@NgModule ( {
38
63
declarations : [ AppComponent ] ,
39
- imports : [
40
- BrowserModule ,
41
- BrowserAnimationsModule ,
42
- IonicModule . forRoot ( ) ,
43
- AppRoutingModule ,
44
- HttpClientModule ,
45
- SharedModule ,
46
- // Firebase
47
- provideFirebaseApp ( ( ) => initializeApp ( environment . firebaseConfig ) ) ,
48
- provideAuth ( ( ) => getAuth ( ) ) ,
49
- FormsModule ,
50
- LottieModule . forRoot ( { player : lottiePlayerFactory } ) ,
51
- // NOTE CC 2021-11-04 not sure if cache causes issues or not https://github.com/ngx-lottie/ngx-lottie/issues/115
52
- // LottieCacheModule.forRoot(),
53
- TemplateComponentsModule ,
54
- TourModule ,
55
- MatomoModule . forRoot ( {
56
- siteId : environment . analytics . siteId ,
57
- trackerUrl : environment . analytics . endpoint ,
58
- } ) ,
59
- MatomoRouterModule ,
60
- ContextMenuModule ,
61
- ] ,
64
+ imports,
62
65
providers : [
63
66
{ provide : RouteReuseStrategy , useClass : IonicRouteStrategy } ,
64
67
HTTP ,
@@ -69,3 +72,32 @@ export function lottiePlayerFactory() {
69
72
bootstrap : [ AppComponent ] ,
70
73
} )
71
74
export class AppModule { }
75
+
76
+ /**
77
+ * Configure app module imports dependent on what firebase features should be enabled
78
+ */
79
+ function loadFirebaseImports ( ) {
80
+ const { firebase } = environment . deploymentConfig ;
81
+
82
+ // Check if any services are enabled, simply return if not
83
+ const enabledServices = Object . entries ( firebase )
84
+ . filter ( ( [ key , v ] ) => v && v . constructor === { } . constructor && v [ "enabled" ] )
85
+ . map ( ( [ key ] ) => key ) ;
86
+ if ( enabledServices . length === 0 ) return ;
87
+
88
+ // Check config exists if services are enabled
89
+ if ( ! firebase . config ) {
90
+ console . warn ( `[Firebase] config missing, services disabled:\n` , enabledServices . join ( ", " ) ) ;
91
+ return ;
92
+ }
93
+
94
+ // Add main firebase initialisation import
95
+ imports . push (
96
+ provideFirebaseApp ( ( ) => initializeApp ( environment . deploymentConfig . firebase . config ) )
97
+ ) ;
98
+
99
+ // Add feature-dependent imports
100
+ if ( firebase . auth . enabled ) {
101
+ imports . push ( provideAuth ( ( ) => getAuth ( ) ) ) ;
102
+ }
103
+ }
0 commit comments