4

Let's say I have a JS file called policies.js and both my Firebase Cloud Functions (and other server object libraries) and Client Web App should comply to the same object interface defined in this policies.js file. Secondly, I also want the object interface to be made available to VSCode's intellisense when developing my client-side web app.

But according to Firebase docs here:

The code for this local module should be stored somewhere other than the node_modules folder within your function's root directory.

In order to make the objects in policies.js accessible by the client web app, I also need to place it inside my hosting folder called scripts so that I can reference it like:

<script src="/scripts/policies.js"></script>

I was thinking: Is there a way to share this policies.js file between Cloud Functions and Client Web App without duplicating and storing it in two different places? There is a similar answer here but the answer does not take into consideration the environmental scope requirements of Firebase Functions. Any ideas/feedback/best practices are welcome! Thanks a lot!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Antonio Ooi
  • 1,601
  • 1
  • 18
  • 32
  • 1
    You will end up duplicating code. The best/easiest way to do this is through a node module that you manage, and include in both end of the project. While the module gets copied, you will have just one source of code to manage. This requires that you use some sort of module bundler on the web side, which is what scalable projects all use. – Doug Stevenson Dec 20 '20 at 17:20
  • @DougStevenson You mean like [browserify](http://browserify.org/)? Hmmm.... I almost forgotten about it! Thanks! – Antonio Ooi Dec 21 '20 at 04:46
  • Hey @DougStevenson your comment should be added as an answer since it solves OP's question. Could you do it? – Ajordat Dec 21 '20 at 10:28
  • Tried with browserify but not working. Hope you guys can help me to take a look at [this post](https://stackoverflow.com/questions/65406191/browserify-not-working-with-module-exports-even-with-standalone-option) if possible, thank you. – Antonio Ooi Dec 22 '20 at 09:44

0 Answers0