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
Hi everyone! I'm trying to build some web apps in a monorepo setting with separating the Firebase SDK (v9) in its own package to act as a general data layer to the different web apps.
My ideal structure would look like the following:
packages/
├─ data // Firebase SDK and functions
├─ app1
├─ app2
The general idea would be to expose functions from the data package to the other web apps that would interact with the Firestore and Storage. The web apps would initialise the Firebase with their own configurations.
I was thinking I could use the modular v9 version to do something like
// in the `data` packageimport{collection,getDocs,Firestore}from'firebase/firestore';exportconstgetPosts=async(db: Firestore)=>{try{constpostsCollection=collection(db,'posts');constquerySnapshot=awaitgetDocs(postsCollection);returnquerySnapshot.docs.map((doc)=>doc.data());}catch(e){console.error('Error reading posts: ',e);}}
and after initialising the Firebase app in the web app like
// firebase.js in `app1`import{initializeApp}from'firebase/app';import{getFirestore}from'firebase/firestore';constfirebaseConfig={/* my Firebase config */};exportconstapp=initializeApp(firebaseConfig);exportconstdb=getFirestore(app);
I could use the imported data-functions from the data package to facilitate the data fetching in the apps (i.e. on mounting or in a server side rendered hook)
// in a component of `app1` import{db}from'./firebase.js';// import the above defined database instanceimport{getPosts}from'data';// import the fetching function from the `data` packageletposts;asynconMount(){try{posts=awaitgetPosts(db);}catch(e){console.error(e);}}
Now unfortunately I've encountered some errors with this approach which I have opened a question on StackOverflow about however here in this discussion I'd be more interested in discussing this approach.
Anyone had success with a similar approach?
Footnote
I have found some resources regarding Firebase in a monorepo setting
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi everyone! I'm trying to build some web apps in a monorepo setting with separating the Firebase SDK (v9) in its own package to act as a general data layer to the different web apps.
My ideal structure would look like the following:
The general idea would be to expose functions from the
data
package to the other web apps that would interact with the Firestore and Storage. The web apps would initialise the Firebase with their own configurations.I was thinking I could use the modular v9 version to do something like
and after initialising the Firebase app in the web app like
I could use the imported data-functions from the
data
package to facilitate the data fetching in the apps (i.e. on mounting or in a server side rendered hook)Now unfortunately I've encountered some errors with this approach which I have opened a question on StackOverflow about however here in this discussion I'd be more interested in discussing this approach.
Anyone had success with a similar approach?
Footnote
I have found some resources regarding Firebase in a monorepo setting
Beta Was this translation helpful? Give feedback.
All reactions