How to deploy some functions to Cloud Functions for Firebase without affecting some other functions?

FirebaseGoogle Cloud-FunctionsFirebase Tools

Firebase Problem Overview


When I run

firebase deploy --only functions

it reads the index.js file and updates all functions exported from that file. If on the previous deploy there was a function named a, and in the current deploy there is no such function, a will be deleted.

In other words, the effect is the same as if all existing functions were deleted and then the all functions from the current index.js file were added.

Is it possible to add/update/delete individual functions?

Firebase Solutions


Solution 1 - Firebase

Firebase CLI tools 3.8.0 has added the ability to deploy specific functions.

firebase deploy --only functions:func1,functions:func2

--only <targets>     
only deploy to specified, comma-separated targets (e.g. "hosting,storage"). For functions, 
can specify filters with colons to scope function deploys to only those functions (e.g. "--only functions:func1,functions:func2"). 
When filtering based on export groups (the exported module object keys), use dots to specify group names 
(e.g. "--only functions:group1.subgroup1,functions:group2)"

Solution 2 - Firebase

The following way worked for me to deploy a particular function without affecting my other functions, where specificFunctionName is the function I wanted to deploy

firebase deploy --only functions:specificFunctionName

To copy the command quickly in terminal:

firebase deploy --only functions:

Solution 3 - Firebase

firebaser here

There is currently no way to deploy a single function with the Firebase CLI. Running firebase deploy will deploy all functions.

We've recently discussed deploying subsets of the functions, but it's not available at the moment - nor can we give a ballpark of if/when it might be.

Update Since Firebase CLI release the ability to deploy single functions is available. See yuku's answer.

Solution 4 - Firebase

firebase deploy --only "functions:<fileName>.<functionName>"

example folder structure:

functions 
  node_modules
  index.js
  smsNotification.js
  ...

You can redeploy just a function in a file with

firebase deploy --only "functions:smsNotification.sendChatNotif"

You can redploy all functions in a file with

firebase deploy --only "functions:smsNotification"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRandy Sugianto &#39;Yuku&#39;View Question on Stackoverflow
Solution 1 - FirebaseRandy Sugianto 'Yuku'View Answer on Stackoverflow
Solution 2 - FirebaseArjunView Answer on Stackoverflow
Solution 3 - FirebaseFrank van PuffelenView Answer on Stackoverflow
Solution 4 - FirebaseDavidView Answer on Stackoverflow