unable to split Firebase functions in multiple files

前端 未结 4 1891
名媛妹妹
名媛妹妹 2021-02-05 10:17

I\'m working with firebase functions and arrived to hundreds of functions, and now it is very hard to manage it in single index.js file as shown in their lots of ex

4条回答
  •  花落未央
    2021-02-05 10:39

    Working code example:

    file structure:

    --firebase.json
    --functions
      --node_modules
      --index.js
      --package.json
      --src
        --groupFunctions.js
        --authFunctions.js
        --storageFunctions.js
    

    index.js file:

    require('./src/groupFunctions.js')(exports);
    require('./src/authFunctions.js')(exports);
    require('./src/storageFunctions.js')(exports);
    

    groupFunctions.js file:

    var functions = require('firebase-functions');
    
    module.exports = function (e) {
        e.onGroupCreate = functions.database.ref('/groups/{groupId}')
            .onWrite(event => {
                console.log(`A group is created in database named:${event.params.groupId}.`);
                // some logic...
                //...
            })
    }
    

    UPDATE: now I have better solution

    The full working code is located at https://github.com/malikasinger1/firebase-functions-with-typescript and it's written with cutting edge tech like typescript and webpack. You may use this as a boilerplate/starter.

提交回复
热议问题