Firebase deploy, ignore all files but public folder

12,185

Use the glob ** to ignore any file or folder in an arbitrary sub-directory.

You can then un-ignore your dist folder with !dist

So your firebase.json file would look like:

{
    "database": {
        "rules": "database.rules.json"
        },
        "hosting": {
            "public": "dist",
            "ignore": [
                "**",
                "!dist/**"
            ],
            "rewrites": [{
                "source": "**",
                "destination": "/index.html"
            }
        ]
    }
}

For newer versions of Firebase:

It appears that new versions of firebase don't allow for the above mentioned method, so instead just define the folders which should be ignored:

{
    "database": {
        "rules": "database.rules.json"
        },
        "hosting": {
            "public": "dist",
            "ignore": [
                "**/node_modules/**",
                "**/src/**",
                "**/public/**"
            ],
            "rewrites": [{
                "source": "**",
                "destination": "/index.html"
            }
        ]
    }
}

You can use the Firebase console to check how many files have been deployed:

  1. Open your Firebase project's Hosting page and take note of the number of files.Firebase Hosting dashboard
  2. Run the command $ tree dist/ (since in this case dist/ is the folder we are serving on Firebase hosting) and take note of the number of files in the build folder. tree for build folder

These should roughly be the same number of files.

Share:
12,185
Ilja
Author by

Ilja

That dev at the local ☕️ shop sipping on late.

Updated on June 05, 2022

Comments

  • Ilja
    Ilja almost 2 years

    I am trying to clean up my deployment process to Firebase, and need to ignore all files besides my /dist aka public folder when deploying files to the hosting. I believe it can be done via ignore setting in firebase.json, but I am not sure how to achieve it besides manually specifying all files.

    example .json:

    {
      "database": {
        "rules": "database.rules.json"
      },
      "hosting": {
        "public": "dist",
        "ignore": [
          // ignore all other files besides dist folder here
        ],
        "rewrites": [
          {
            "source": "**",
            "destination": "/index.html"
          }
        ]
      }
    }