Getting Started
1. Install SvelteFireTS and Firebase
npm i -D sveltefirets firebase or pnpm add -D sveltefirets firebase
2. Add Firebase Project Config Via Env Variables
- Add your Firebase config object for the project you use to develop with to a
.envfile in the same folder assvelte.config.jsas a string:
PUBLIC_FIREBASE_CONFIG={"apiKey":"...","authDomain":"YOURPROJECTID.firebaseapp.com","databaseURL":"https://YOURPROJECTID.firebaseio.com","projectId":"YOURPROJECTID","storageBucket":"YOURPROJECTID.appspot.com","messagingSenderId":"...","appId":"...","measurementId":"..."}
-
SvelteFireTS will use these values the first time it is called to initialize. This will save your client side start time a few moments on pages that don't utilize Firebase if applicable.
-
If needing to access the config values in your site, just
import { firebaseConfig } from 'sveltefirets; -
Any config placed into your hosting provider's env variables (e.g. Vercel) under the
PUBLIC_FIREBASE_CONFIGkey will automatically override these and allow for easy use of different projects between dev and production.- When using SvelteFireTS in non-SvelteKit environments, a file that exports
PUBLIC_FIREBASE_CONFIGas a string will need to be aliased to$env/static/publicas this library expects that to be available. If this is not workable in your use case, feel free to submit a PR that updatesconfig.tstoprocess.env.PUBLIC_FIREBASE_CONFIGserver-side orwindow.PUBLIC_FIREBASE_CONFIGclient side.
- When using SvelteFireTS in non-SvelteKit environments, a file that exports
-
If wanting to share config between projects in a monorepo set the
envDirproperty in yourvite.config.jsto../or../../as applicable and place the.envfile in the repo root.
3. Use
You are ready to use SvelteFireTS in any manner described in these docs!