简体   繁体   English

如何获取“ firebase deploy --only functions”命令以在functions /目录中使用package.json?

[英]How can I get “firebase deploy --only functions” command to use the package.json in the functions/ directory?

I've got the standard app structure for a Firebase/Angular application. 我已经有了Firebase / Angular应用程序的标准应用程序结构。

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

The problem is that when I run firebase deploy --only functions , the predeploy hooks that I've defined in firebase.json , are called from inside the root/ directory, and not from inside root/functions/ directory. 问题是,当我运行firebase deploy --only functions ,我在已经定义了预先部署挂钩firebase.json ,由内而外都称为root/目录下,而不是从内部root/functions/目录。

So for example, in root/package.json I have 例如,在root/package.json中,

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

but in root/functions/package.json I have 但是在root/functions/package.json

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

and in my firebase.json file I have 在我的firebase.json文件中

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

No matter whether I am in root/ or root/functions , when I run firebase deploy --only functions I get hello1 无论我是在root/还是root/functions ,当我运行firebase deploy --only functions我会得到hello1

How do I configure my Firebase tools to use the configurations (ie namely the package.json stuff) from functions/ when I run deploy --only functions ? 当我运行deploy --only functions时,如何配置Firebase工具以使用来自functions/的配置(即package.json内容)?

It seems the best way to get this working, according to the Firebase Typescript docs , is to specify the predeploy hook as follows 根据Firebase Typescript文档 ,似乎最好的方法是按照以下方式指定predeploy挂钩:

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

This calls npm run build from inside the functions directory, so it will call the build script in functions/package.json and not the project root's package.json 这从functions目录内部调用npm run build ,因此它将在functions/package.json而不是项目根目录的package.json调用build脚本package.json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM