# sveltekit-adapter-firebase

> ![npm](https://img.shields.io/npm/v/sveltekit-adapter-firebase?color=ff00) [![codecov](https://codecov.io/gh/simonnepomuk/monorepo/branch/main/graph/badge.svg?token=P2OL5DVRU9)](https://codecov.io/gh/simonnepomuk/monorepo) ![CI](https://github.com/simonne

Latest version **0.1.13** (published 2022-12-03) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install sveltekit-adapter-firebase
pnpm add sveltekit-adapter-firebase
yarn add sveltekit-adapter-firebase
bun add sveltekit-adapter-firebase
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.13 |
| Published | 2022-12-03 |
| First published | 2022-10-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 665.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | simonnepomuk |
| Keywords | svelte, sveltekit, sveltekit-adapter, firebase, cloud-functions, cloud-run, serverless, ssr |

## Links

- npm: https://www.npmjs.com/package/sveltekit-adapter-firebase
- Repository: https://github.com/simonnepomuk/monorepo
- Homepage: https://github.com/simonnepomuk/monorepo#readme
- Issues: https://github.com/simonnepomuk/monorepo/issues
- npm.io page: https://npm.io/package/sveltekit-adapter-firebase

## Recent versions

- 0.1.13 (latest) — 2022-12-03
- 0.1.12 — 2022-11-23
- 0.1.11 — 2022-11-18
- 0.1.10 — 2022-11-17
- 0.1.9 — 2022-11-05
- 0.1.8 — 2022-11-02
- 0.1.7 — 2022-11-02
- 0.1.6 — 2022-11-02
- 0.1.5 — 2022-11-02
- 0.1.4 — 2022-11-01
- 0.1.3 — 2022-11-01
- 0.1.2 — 2022-10-29
- 0.1.0 — 2022-10-28
- 0.0.6 — 2022-10-28
- 0.0.5 — 2022-10-26
- … 4 more at https://npm.io/package/sveltekit-adapter-firebase/versions

## README

# sveltekit-adapter-firebase

![npm](https://img.shields.io/npm/v/sveltekit-adapter-firebase?color=ff00)
[![codecov](https://codecov.io/gh/simonnepomuk/monorepo/branch/main/graph/badge.svg?token=P2OL5DVRU9)](https://codecov.io/gh/simonnepomuk/monorepo)
![CI](https://github.com/simonnepomuk/monorepo//actions/workflows/main.yml/badge.svg)  
[Firebase](https://firebase.google.com/) adapter for
[SvelteKit](https://github.com/sveltejs/kit).

- SSR on
  [Cloud Functions](https://firebase.google.com/docs/hosting/functions)
- Supports CloudFunctions v2!
  - [Concurrency](https://firebase.google.com/docs/functions/beta/manage-functions#allow_concurrent_requests)
  - Easier [CORS](https://firebase.google.com/docs/functions/beta/http-events#configuring_cors_cross-origin_resource_sharing)
  - Built on [CloudRun](https://cloud.google.com/run)
  - New trigger types
  - Up to 1hr timeout
- Local production testing with
  [Firebase Emulator](https://firebase.google.com/docs/emulator-suite)

## Getting started

In your standard SvelteKit project:

- `npm i -D sveltekit-adapter-firebase`
- add adapter to `svelte.config.js`:

```diff
+import adapter from "sveltekit-adapter-firebase";

/** @type {import('@sveltejs/kit').Config} */
export default {
  kit: {
+   adapter: adapter(),
  },
};
```

- add `firebase.json` next to build folder:

```
{
  "hosting": {
    "public": "build",
    "ignore": [
      "**/.firebase/**"
    ],
    "cleanUrls": true, //needed to serve prerendered pages without adding .html in the url
    "rewrites": [
      {
        "source": "**",
        "function": "handler",
      }
    ]
  },
  "functions": [
    {
      "source": "build",
    }
  ]
}
```

## Configuration

The following snippet shows the default configuration.  
V2 is used by default because it allows for concurrency which should drastically reduce costs and cold-starts.  
For further documentation on the functionOptions parameter visit the
official [Firebase documentation](https://firebase.google.com/docs/functions/beta/reference/firebase-functions.https.httpsoptions.md)
.

```
/** @type {import('@sveltejs/kit').Config} */
export default {
  kit: {
    adapter: adapter({
      outDir: 'build',
      functionName: 'handler', //needs to correspond to function hosting.rewrites[0].function property in firebase.json
      nodeVersion: '16', // '16' or '14'
      version: 'v1', // 'v1' or 'v2'
      functionOptions: { // functionOptions are only available in v2
        concurrency: 500 // max. 1000
      }
    }),
  },
};
```

### Region

To configure a region for the SvelteKit Server the `firebase.json` also needs to be adapted as follows  
`svelte.config.js`

```
/** @type {import('@sveltejs/kit').Config} */
export default {
  kit: {
    adapter: adapter({
      functionOptions: {
        region: "europe-west1"
      }
    }),
  },
};
```

`firebase.json`

```
{
  "hosting": {
    "public": "build",
    "ignore": [
      "**/.firebase/**"
    ],
    "cleanUrls": true,
    "rewrites": [
      {
        "source": "**",
        "function": "handler",
        "region": "europe-west1"
      }
    ]
  },
  "functions": [
    {
      "source": "build",
    }
  ]
}
```

### Monorepo

Through the `outDir` configuration option the adapter should provide monorepo support (tested with Nx).  
For monorepos with a workspace package.json like Nx you would need some form of scripting to generate the correct
package.json with all dependencies.  
`svelte.config.js`

```
/** @type {import('@sveltejs/kit').Config} */
export default {
  kit: {
    adapter: adapter({
      outDir: "../../dist/apps/frontend"
    }),
  },
};
```

`firebase.json` in project root:

```
{
  "hosting": {
    "public": "dist/apps/frontend",
    "ignore": [
      "**/.firebase/**"
    ],
    "cleanUrls": true,
    "rewrites": [
      {
        "source": "**",
        "function": "handler",
      }
    ]
  },
  "functions": [
    //api is added here to present how a backend service might be integrated
    {
      "codebase": "api",
      "source": "dist/apps/api",
      "runtime": "nodejs16"
    },
    {
      "codebase": "frontend",
      "source": "dist/apps/frontend",
    }
  ]
}
```

## Beware

`functionOptions` are currently only available on v2 functions.
If `functionOptions` for v1 are in high demand this might get added later on (**open to PR**).

V2 also requires the _Blaze_ subscription but offers a free tier of 2 million requests per month.

Firebase Web Frameworks are currently not supported.

---
_Source: https://npm.io/package/sveltekit-adapter-firebase · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
