【问题标题】:How can I get "firebase deploy --only functions" command to use the package.json in the functions/ directory?如何获得“firebase deploy --only functions”命令以使用函数/目录中的 package.json?
【发布时间】:2019-01-01 18:56:48
【问题描述】:

我已经有了 Firebase/Angular 应用程序的标准应用程序结构。

- functions/
   |--- index.ts
   |--- package.json
- src/
   |--- app/
   |     |--- (angular stuff)
   |--- index.html
   |--- ...
- package.json
- firebase.json

问题是当我运行firebase deploy --only functions 时,我在firebase.json 中定义的预部署挂钩是从root/ 目录内部调用的,而不是从root/functions/ 目录内部调用的。

例如,在root/package.json 我有

{
  "name": "functions",
  "scripts": {
    "echo": "echo 'hello1'"
  },
...
}

但在 root/functions/package.json 我有

{
  "name": "functions",
  "scripts": {
    "echo": "echo 'hello2'"
  },
...
}

在我的firebase.json 文件中,我有

{
  ...
  "functions": {
    "predeploy": [
      "npm run echo"
    ]
  },

无论我是在root/ 还是root/functions,当我运行firebase deploy --only functions 时,我都会得到hello1

当我运行 deploy --only functions 时,如何配置我的 Firebase 工具以使用来自 functions/ 的配置(即 package.json 的东西)?

【问题讨论】:

    标签: firebase npm google-cloud-functions package.json firebase-cli


    【解决方案1】:

    根据the Firebase Typescript docs,似乎最好的方法是指定predeploy钩子,如下所示

    {
       "functions": {
         "predeploy": "npm --prefix functions run build",
       }
     }
    

    这会从functions 目录内部调用npm run build,因此它将调用functions/package.json 中的build 脚本,而不是项目根目录的package.json

    【讨论】:

      猜你喜欢
      • 2017-08-02
      • 2018-09-08
      • 2020-12-14
      • 2018-10-15
      • 2021-05-12
      • 2020-03-19
      • 1970-01-01
      • 2020-06-17
      相关资源
      最近更新 更多