简体   繁体   中英

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.

- 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.

So for example, in root/package.json I have

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

but in root/functions/package.json I have

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

and in my firebase.json file I have

{
  ...
  "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

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 ?

It seems the best way to get this working, according to the Firebase Typescript docs , is to specify the predeploy hook as follows

{
   "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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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