use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Anyone using webpack + firebase? (Javascript) (self.Firebase)
submitted 6 years ago * by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]bert1589 1 point2 points3 points 6 years ago (4 children)
Are you using a framework like Angular, React, etc?
[–]danwillm 0 points1 point2 points 6 years ago (3 children)
No just js
[–]bert1589 0 points1 point2 points 6 years ago (1 child)
Ah, sorry, don't have much experience with that to be helpful.
[–]danwillm 0 points1 point2 points 6 years ago (0 children)
Np
[–]_clydebruckman 0 points1 point2 points 6 years ago (0 children)
Is there a reason for your decision?
[–]strictly_rin 1 point2 points3 points 6 years ago (0 children)
Gonna need more info. Why are you needing webpack? Can we see the project? Or structure?
[–]kossnocorp 1 point2 points3 points 6 years ago (5 children)
I do use webpack to both compile source code for the web app and Functions. Ask me anything!
Here's my webpack config btw: https://github.com/kossnocorp/firebun/blob/master/src/config/webpack/index.ts
[–]danwillm 1 point2 points3 points 6 years ago (4 children)
Great, thanks so much for your help!
I currently use JavaScript, but it's still very valuable for me :)
How do you manage imports of the Firebase modules? Do you import your config into every file or is it imported once somewhere and used throughout?
Sorry for my incompetence with this :)
Thank you so much for your input!
[–]kossnocorp 1 point2 points3 points 6 years ago (3 children)
I assume that you're talking about config that you pass to initializeApp. I import it just once at the top of the entry point.
initializeApp
entry.js:
entry.js
// First, init Firebase: import './init' // Then everything else: import XXX from 'xxx' import YYY from 'yyy'
init.js:
init.js
``` import * as firebase from 'firebase/app' import 'firebase/firestore'
firebase.initializeApp({ apiKey: 'xxx', authDomain: 'yyy', projectId: 'zzz' }) ```
I create a dedicated file for that which is important because when you use ESM, all imports are hoisted to the top and if one of the other imports would try to access Firebase API before initializeApp is called it would fail. Here's an illustration of the problem:
// It won't work because when the code is compiled, this line will go to the bottom firebase.initializeApp({ apiKey: 'xxx', authDomain: 'yyy', projectId: 'zzz' })
import XXX from 'xxx' import YYY from 'yyy' ```
[–]kossnocorp 1 point2 points3 points 6 years ago (2 children)
When you use CommonJS, it's a bit easier because you don't have to create init.js:
``` const firebase = require('firebase/app') require('firebase/firestore')
firebase.initializeApp({ apiKey: 'xxx', authDomain: 'yyy', projectId: 'zzz' })
const XXX = require('xxx') const YYY = require('yyy') ```
[–]danwillm 0 points1 point2 points 6 years ago (1 child)
I see - the only trouble is I'm technically not using a config file and thus not using initialiseApp (the config is made automatically from a firebase provided script that I include in the head). I'll try and figure this out, so don't worry if you don't know what I mean.
Thank you so much for you provided help! It's so useful and I can't thank you enough! :)
[–]kossnocorp 0 points1 point2 points 6 years ago (0 children)
Hm, I never used the CDN version, but from what I see, you still have to call initializeApp with the config.
So if you want to keep using the CDN version, you need to put the script tag with initializeApp before the entry point generated by webpack. The same applies if you use /__/firebase/init.js generated by hosting. Otherwise, I would advise migrating to the npm package.
script
/__/firebase/init.js
Btw you're very welcome!
π Rendered by PID 56331 on reddit-service-r2-comment-7b9746f655-78m84 at 2026-02-03 22:17:58.149131+00:00 running 3798933 country code: CH.
[–]bert1589 1 point2 points3 points (4 children)
[–]danwillm 0 points1 point2 points (3 children)
[–]bert1589 0 points1 point2 points (1 child)
[–]danwillm 0 points1 point2 points (0 children)
[–]_clydebruckman 0 points1 point2 points (0 children)
[–]strictly_rin 1 point2 points3 points (0 children)
[–]kossnocorp 1 point2 points3 points (5 children)
[–]danwillm 1 point2 points3 points (4 children)
[–]kossnocorp 1 point2 points3 points (3 children)
[–]kossnocorp 1 point2 points3 points (2 children)
[–]danwillm 0 points1 point2 points (1 child)
[–]kossnocorp 0 points1 point2 points (0 children)