Search code examples
javascriptfirebasegoogle-cloud-functionsfirebase-cli

How to deploy functions from other directory than '/functions'?


David in his repo:

https://github.com/davideast/react-ssr-firebase-hosting

has the file with firebase functions index.js in the main root, not in the /functions directory.

However, if I do the same and drop my index.js file to main root, if I do firebase deploy --only functions it says in the console:

i  deploying functions

Error: functions\index.js does not exist, can't deploy Firebase Functions

Q: How is it possible that he made it work? How can I do the same and deploy successfully functions from other dir than /functions?

Thanks

firebase.json

{
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "function": "ssrapp"
      }
    ]
  },
  "functions": {
     "source": "/"
  }
}

Solution

  • The project workspace that you create with the Firebase CLI contains a file called firebase.json that has a stanza for Cloud Functions that looks like this:

    "functions": {
      "predeploy": [
        "npm --prefix $RESOURCE_DIR run lint"
      ],
      "source": "functions"
    }
    

    That "source" property defines the name of the folder that contains the code that will run on Cloud Functions. You can change that to whatever you want.