13

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"
      }
    ]
  }
}
AL.
  • 36,815
  • 10
  • 142
  • 281
Ilja
  • 44,142
  • 92
  • 275
  • 498

3 Answers3

18

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.

Shahzeb Khan
  • 437
  • 3
  • 12
Dan
  • 769
  • 6
  • 15
  • 1
    For some reason this is not working with firebase version 3.15.0 – Mirko Akov Nov 15 '17 at 10:40
  • I don't understand why the need to create an additional folder called `dist` instead of leaving the `public` folder to function as `dist` folder. Simply because the `dist` looks cooler or it serves other important purpose? Even the module bundler can be configured to use `public` as `dist` right? – Antonio Ooi Dec 28 '22 at 17:37
1

The ignore attribute specifies the files to ignore on deploy. It can take glob pattern the same way that Git handles .gitignore.

The following are the default values for the files to ignore:

"hosting": {
  // ...

  "ignore": [
    "firebase.json",  // the Firebase configuration file (this file)
    "**/.*",  // files with a leading period should be hidden from the system
    "**/node_modules/**",  // contains dependencies used to create your site but not run it

    "**/someOtherFolder/**"  // this is will exclude the folder with the name entered
    "**someOtherFile**" // this will exclude that particular file
  ]
}
Dženis H.
  • 7,284
  • 3
  • 25
  • 44
0

!(pattern) Matches anything that does not match any of the patterns provided.

* Only matches files and folders in the root of the public directory

{
  "hosting": {
    "public": "dist",
    "ignore": ["**, !*"],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}
cocacrave
  • 2,453
  • 4
  • 18
  • 30