如何从'/ functions'以外的其他目录部署函数?

Pat*_*kkx 6 javascript firebase google-cloud-functions firebase-cli

大卫在他的回购中:

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

具有firebase功能的文件index.js在主根目录中,而不是/functions目录中.

但是,如果我这样做并将我的index.js文件放到主根,如果我这样做firebase deploy --only functions,请在控制台中说:

i  deploying functions

Error: functions\index.js does not exist, can't deploy Firebase Functions
Run Code Online (Sandbox Code Playgroud)

:他怎么可能让它发挥作用?我怎么能这样做并从其他目录成功部署功能/functions

谢谢

firebase.json

{
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "function": "ssrapp"
      }
    ]
  },
  "functions": {
     "source": "/"
  }
}
Run Code Online (Sandbox Code Playgroud)

Dou*_*son 19

使用Firebase CLI创建的项目工作区包含一个名为firebase.json的文件,该文件具有云函数的节,如下所示:

"functions": {
  "predeploy": [
    "npm --prefix $RESOURCE_DIR run lint"
  ],
  "source": "functions"
}
Run Code Online (Sandbox Code Playgroud)

该"source"属性定义包含将在Cloud Functions上运行的代码的文件夹的名称.您可以将其更改为您想要的任何内容.

  • 功能字段的"源"是否记录在任何地方? (3认同)
  • 你的“函数”节看起来不像我的,它不应该包含任何重写。重写是为了托管。托管是与 Cloud Functions 不同的产品,因此它们具有不同的配置。您的“functions”节应该有一个名为“source”的直接子属性,它是包含您要部署的源的文件夹的名称。 (2认同)

小智 10

如果你想用你的根目录作为您的文件夹功能,只需改变你的source钥匙.在你的firebase.json

  "functions": {
    "source": ".",
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ]
  }
Run Code Online (Sandbox Code Playgroud)

这将index.js在根目录中查找您的文件(记住将所有其他文件也移动到您的根目录)。

文档:https : //firebase.google.com/docs/functions/manage-functions#deploy_functions