返回 Skills 目录
firebase/agent-skills已通过检查

SKILL DETAIL

firebase-hosting-basics

firebase/agent-skills/firebase-hosting-basics

此技能提供使用 Firebase Hosting 的说明和参考,Firebase Hosting 是一项快速、安全的托管服务,适用于您的 Web 应用、静态和动态内容以及微服务。 Firebase Hosting 为开发者提供生产级 Web 内容托管。通过单个命令,您可以将 Web 应用部署到全球 CDN(内容分发网络),并同时提供静态和动态内容。主要功能包括:快速内容交付(文件缓存在全球 CDN 边缘的 SSD 上)、默认安全(内置零配置 SSL)、预览渠道(在临时预览 URL 上查看和测试更改)、GitHub 集成(使用 GitHub Actions 自动化预览和部署)以及动态内容(使用 Cloud Functions 或 Cloud Run 提供动态内容和微服务)。 选择 Firebase Hosting 的适用场景:部署静态站点(HTML/CSS/JS)、简单的 SPA(如 React、Vue,无 SSR)或希望通过 CLI 完全控制构建和部署过程。对于使用 Next.js 或 Angular 等全栈框架、需要服务器端渲染(SSR)或 ISR、或希望零配置的“git push 到部署”工作流,请选择 Firebase App Hosting。

安装量 · 576查看来源

Installation

npx skills add https://github.com/firebase/agent-skills --skill firebase-hosting-basics

技能文件

SKILL.md

最近同步 · 2026年10月23日

references/configuration.md›
# Hosting Configuration (`firebase.json`)

The `hosting` section of `firebase.json` configures how your site is deployed
and served.

## Key Attributes

### `public` (Required)

Specifies the directory to deploy to Firebase Hosting.

```json
"hosting": {
  "public": "public"
}
```

### `ignore` (Optional)

Files to ignore on deploy. Uses glob patterns (like `.gitignore`). **Default
ignores:** `firebase.json`, `**/.*`, `**/node_modules/**`

### `redirects` (Optional)

URL redirects to prevent broken links or shorten URLs.

```json
"redirects": [
  {
    "source": "/foo",
    "destination": "/bar",
    "type": 301
  }
]
```

### `rewrites` (Optional)

Serve the same content for multiple URLs, useful for SPAs or Dynamic Content.

```json
"rewrites": [
  {
    "source": "**",
    "destination": "/index.html"
  },
  {
    "source": "/api/**",
    "function": "apiFunction"
  },
  {
    "source": "/container/**",
    "run": {
      "serviceId": "helloworld",
      "region": "us-central1"
    }
  }
]
```

### `headers` (Optional)

Custom response headers.

```json
"headers": [
  {
    "source": "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
    "headers": [
      {
        "key": "Access-Control-Allow-Origin",
        "value": "*"
      }
    ]
  }
]
```

### `cleanUrls` (Optional)

If `true`, drops `.html` extension from URLs.

```json
"cleanUrls": true
```

### `trailingSlash` (Optional)

Controls trailing slashes in static content URLs.

- `true`: Adds trailing slash.
- `false`: Removes trailing slash.

## Full Example

```json
{
  "hosting": {
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ],
    "cleanUrls": true,
    "trailingSlash": false
  }
}
```
references/deploying.md›
# Deploying to Firebase Hosting

## Standard Deployment

To deploy your Hosting content and configuration to your live site:

```bash
npx -y firebase-tools@latest deploy --only hosting
```

This deploys to your default sites (`PROJECT_ID.web.app` and
`PROJECT_ID.firebaseapp.com`).

## Preview Channels

Preview channels allow you to test changes on a temporary URL before going live.

### Deploy to a Preview Channel

```bash
npx -y firebase-tools@latest hosting:channel:deploy CHANNEL_ID
```

Replace `CHANNEL_ID` with a name (e.g., `feature-beta`). This returns a preview
URL like `PROJECT_ID--CHANNEL_ID-RANDOM_HASH.web.app`.

### Expiration

Channels expire after 7 days by default. To set a different expiration:

```bash
npx -y firebase-tools@latest hosting:channel:deploy CHANNEL_ID --expires 1d
```

## Cloning to Live

You can promote a version from a preview channel to your live channel without
rebuilding.

```bash
npx -y firebase-tools@latest hosting:clone SOURCE_SITE_ID:SOURCE_CHANNEL_ID TARGET_SITE_ID:live
```

**Example:** Clone the `feature-beta` channel on your default site to live:

```bash
npx -y firebase-tools@latest hosting:clone my-project:feature-beta my-project:live
```
SKILL.md›
---
name: firebase-hosting-basics
description: >-
  Deploys and configures classic Firebase Hosting for static websites, single-page apps (SPAs), and microservices. Use when deploying static sites/SPAs, setting up custom domains, configuring firebase.json hosting settings (redirects, rewrites, headers, multi-site), or managing preview channels. Don't use for Firebase App Hosting (Next.js/SSR), Auth, Firestore queries/rules, Data Connect, or Crashlytics.
metadata:
  author: Google LLC
  category: Serverless
---

# hosting-basics

This skill provides instructions and references for working with Firebase
Hosting, a fast and secure hosting service for your web app, static and dynamic
content, and microservices.

## Overview

Firebase Hosting provides production-grade web content hosting for developers.
With a single command, you can deploy web apps and serve both static and dynamic
content to a global CDN (content delivery network).

**Key Features:**

- **Fast Content Delivery:** Files are cached on SSDs at CDN edges around the
  world.
- **Secure by Default:** Zero-configuration SSL is built-in.
- **Preview Channels:** View and test changes on temporary preview URLs before
  deploying live.
- **GitHub Integration:** Automate previews and deploys with GitHub Actions.
- **Dynamic Content:** Serve dynamic content and microservices using Cloud
  Functions or Cloud Run.

## Hosting vs App Hosting

**Choose Firebase Hosting if:**

- You are deploying a static site (HTML/CSS/JS).
- You are deploying a simple SPA (React, Vue, etc. without SSR).
- You want full control over the build and deploy process via CLI.

**Choose Firebase App Hosting if:**

- You are using a supported full-stack framework like Next.js or Angular.
- You need Server-Side Rendering (SSR) or ISR.
- You want an automated "git push to deploy" workflow with zero configuration.

## Instructions

### 1. Configuration (`firebase.json`)

For details on configuring Hosting behavior, including public directories,
redirects, rewrites, and headers, see
[configuration.md](references/configuration.md).

### 2. Deploying

For instructions on deploying your site, using preview channels, and managing
releases, see [deploying.md](references/deploying.md).

### 3. Emulation

To test your app locally:

```bash
npx -y firebase-tools@latest emulators:start --only hosting
```

This serves your app at `http://localhost:5000` by default.