This project is an example of how to share code between firebase functions and other packages using a monorepo.
The shared code is a monorepo package that is imported by both the firebase functions and the web app. Normally firebase functions have a hard time with symlinked packages in monorepos, since the source files are uploaded to Google Cloud where the dependencies are then installed according to the package.json. However, we resolve this issue by using vite lib mode to bundle the shared code into the firebase functions source code while leaving all other dependencies external.
This solution is inspired by a suggestion by benrandja-akram on Github, check out the issue here.
- Install dependencies
npm install
- Run firebase functions emulator
npm run emu
- Open another terminal and run development mode
npm run dev
Now you can see that both the firebase functions and the development mode are running and sharing the same code.
Since vite pre-bundles dependencies and caches them in the browser, you may need to temporarily disable the network cache when making changes to the shared code and developing in the web app.