首页 > 解决方案 > 部署函数时,哪些文件会发送到 Firebase 云函数环境?

问题描述

假设functions我的 Firebase 应用程序的文件夹中有以下结构。

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

问题

我想了解部署index.js文件时发生了什么。

注意:functions文件夹位于我的 Firebase 项目根文件夹中,其中有一个firebase.json文件和部署所需的所有其他内容。

PS:我知道在 SO 上问多个问题并不是最佳实践,但它们都与主要问题有关:“运行时,哪些文件和文件夹被部署到云功能环境firebase deploy --only functions

标签: javascriptfirebasegoogle-cloud-functions

解决方案


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.


推荐阅读