Reputation: 31425
Let's say I have the following structure inside my functions
folder for my Firebase app.
functions
> node_modules // INSTALLED NODE MODULES
> distApp // REACT APP FILES TRANSPILED WITH BABEL
App.js
index.html
> distFunctions // FUNCTION FILES TRANSPILED WITH BABEL
function1.js // SOME OF THEM USE FILES FROM 'distApp' FOLDER
function2.js
> src // FUNCTION FILES WRITTEN IN ES6+
function1.js
function2.js
indexES6.js // CLOUD FUNCTIONS index.js WRITTEN IN ES6+
index.js // CLOUD FUNCTIONS index.js TRANSPILED WITH BABEL
package.json
QUESTION
I would like to understand what happend when I deploy my index.js
file.
What files are going to be available inside my Node.js
environment? Do all files inside my functions
folder (and subfolders) are going to be sent to my Node.js
environment?
What if none of my functions use (require) a file named someFile.xxx
. But that file is sitting there inside of one of my functions
subfolders. Is it going to be sent to the Cloud Functions environment?
The node_modules
folder is ignored during the deployment and packages are installed inside the Node.js environment in the Cloud. Am I right?
NOTE: This functions
folder lives inside my Firebase project root folder, where I have a firebase.json
file and everything else needed for deployment.
PS: I know it's not best practice to ask more than one question here on SO, but they're all related to the main question: "Exactly which files and folders are deployed to the cloud functions environment when you run firebase deploy --only functions
"?
Upvotes: 3
Views: 541
Reputation: 317542
Everything from your functions folder gets deployed, except node_modules. It doesn't matter what your index.js contains.
Cloud Functions will reconstitute your node_modules folder on the backend by running npm install
. So, the contents of your package.json matters a lot.
In the end, Cloud Functions builds a docker image and puts all those files and modules from your functions folder into it, and it will all be available when your function executes.
Upvotes: 4