javascript - 部署函数时,哪些文件会发送到 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
文件时发生了什么。
我的环境中将提供哪些文件
Node.js
?我的functions
文件夹(和子文件夹)中的所有文件都将发送到我的Node.js
环境吗?如果我的函数都没有使用(需要)名为
someFile.xxx
. 但是该文件位于我的一个functions
子文件夹中。它会被发送到 Cloud Functions 环境吗?该
node_modules
文件夹在部署期间被忽略,并且包安装在云中的 Node.js 环境中。我对吗?
注意:此functions
文件夹位于我的 Firebase 项目根文件夹中,其中有一个firebase.json
文件和部署所需的所有其他内容。
PS:我知道在 SO 上问多个问题并不是最佳实践,但它们都与主要问题有关:“运行时,哪些文件和文件夹被部署到云功能环境firebase deploy --only 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.
推荐阅读
- bash - 删除 bash 中最后一次出现的字符串
- eclipse - HANA Eclipse - 项目资源管理器“没有连接到数据库”
- javascript - 如何在 Cypress 中测试 Slate JS 行为
- php - 如何在 PHP 数组中找到填充的索引?
- python - 使用 mypy 时在 python 中正确键入异常/错误元组
- html - 为什么在使用“padding: 10px;!imprtant;”时我的导航栏上没有颜色
- webpack - Webpack 无法解析相对于包路径的模块
- git - Git - 多个遥控器是否可以有多个 .gitignore?
- python-3.x - 应用于 Discord 机器人的 API 需要多个参数
- laravel-5 - 在 Laravel 中自动启用维护模式