22

Question:

How to upload a single file to firebase without deleting existing files?

Details:

  • Intent: upload single file without deleting existing files on server

  • Usage: have separate directories on local machine each uploading to a specific folder on server

  • What I've tried: overriding the public dir with firebase deploy -p file.txt, this results in setting root public dir to use that dir.

adamszone
  • 223
  • 1
  • 2
  • 5

2 Answers2

20

Disclosure: I work at Firebase

Firebase hosting's command line tools currently requires that you have the entire web site locally, even though it will only upload the files that were modified since the last deploy.

So your only workaround for not would be to have a single machine where all those directories exist, e.g. something like a build or staging server.

We are aware that this is limiting the number of cases that it can be used for.

Update (December 2018): Firebase Hosting now has a REST API. While this still doesn't officially allow you to deploy a single file, you can use it creatively to get what you want. See my Gist here: https://gist.github.com/puf/e00c34dd82b35c56e91adbc3a9b1c412

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Hi Frank, thanks for the quick response. This was the work-around I was using, seems to work, I didn't know if it was best-practice. Wasn't sure if it was uploading all files every `firebase deploy` call or not. As it's a CDN based service makes sense that it would have this limitation. – adamszone Jun 07 '15 at 00:53
  • Is that still the case today (2018) that firebase can only update the whole project? – Marcos Silva Mar 14 '18 at 17:09
  • 1
    @Frank Van Puffelen... Is it possible to support deploying single files on the platform but just in the future? Or this this something the architecture won't ever support? – OpTech Marketing Mar 23 '18 at 16:58
  • 1
    this question is three years old, any update on this? – pedrommuller Jun 21 '18 at 22:39
  • 1
    Not yet. But keep watching the Firebase blog and release notes for exciting updates on this front. :-) – Frank van Puffelen Jun 22 '18 at 03:34
  • 1
    any news about this issue? – Guilherme Simão Couto Sep 09 '19 at 18:53
  • 1
    The CLI will only upload files that have been changed since the last deploy. But in order for it to determine that, you'll still need to have all file locally. If you only have the files you want to deploy, you can use the script in the gist I linked. – Frank van Puffelen Sep 09 '19 at 19:38
  • 2
    With release of firebase-tools v11.1.0 the underlying `firebase-tools/lib/api` object no longer has the request method - unsure of a current way to upload a single file without having the whole published hosting site locally - see https://github.com/firebase/firebase-tools/pull/4629 – Mike Hardy Jun 14 '22 at 19:42
  • 1
    Oof... good catch Mike. The Hosting team is aware of this and looking at creating a script that does the same thing differently. – Frank van Puffelen Jun 14 '22 at 21:58
-1

You can modify the firebase.json file to add objects in the rewrites attribute to upload only the files you want. For example:

{
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [{
      "source": "index.html",
      "destination": "/index.html"
    },
    {
      "source": "css/style.css",
      "destination": "/css/style.css"
    }]
  }
}