npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-plugin-firebase-config

v0.2.3

Published

A Vite plugin to automatically sync Firebase configuration from environment variables to static files

Downloads

157

Readme

vite-plugin-firebase-config

npm version License: MIT

A Vite plugin that automatically syncs Firebase configuration from environment variables to static files, solving the common issue of Firebase Auth callbacks requiring static configuration files.

🎯 Problem This Solves

When using Firebase Authentication with static hosting (S3, CloudFront, Vercel, etc.), Firebase SDK requires a static /__/auth/init.json file for OAuth callbacks. Managing this file across different environments (dev, staging, prod) can be error-prone and lead to configuration drift.

This plugin automatically:

  • ✅ Reads Firebase config from environment variables
  • ✅ Generates public/__/auth/init.json automatically
  • ✅ Keeps config in sync between your code and static files
  • ✅ Supports multiple environments (dev, staging, production)
  • ✅ Validates configuration to catch errors early
  • ✅ Hot-reloads during development

📦 Installation

npm install -D vite-plugin-firebase-config
# or
pnpm add -D vite-plugin-firebase-config
# or
yarn add -D vite-plugin-firebase-config

🚀 Quick Start

1. Add to vite.config.ts

import { defineConfig } from 'vite'
import firebaseConfig from 'vite-plugin-firebase-config'

export default defineConfig({
  plugins: [
    firebaseConfig()
  ]
})

2. Set Environment Variables

Create .env files for different environments:

# .env.development
VITE_FIREBASE_API_KEY=your-dev-api-key
VITE_FIREBASE_AUTH_DOMAIN=localhost:5173
VITE_FIREBASE_PROJECT_ID=your-project-id
VITE_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=123456789
VITE_FIREBASE_APP_ID=1:123:web:abc
VITE_FIREBASE_MEASUREMENT_ID=G-XXXXXXXXXX

# .env.production
VITE_FIREBASE_API_KEY=your-prod-api-key
VITE_FIREBASE_AUTH_DOMAIN=your-domain.com
# ... other production values

3. Done! 🎉

The plugin will automatically generate public/__/auth/init.json based on your environment variables.

🔧 Configuration

Basic Options

firebaseConfig({
  // Configuration source: 'env' or 'inline'
  source: 'env',
  
  // Environment variable prefix
  envPrefix: 'VITE_FIREBASE_',
  
  // Output configuration
  output: {
    path: 'public/__/auth/init.json',
    indent: 2,
    addWarningComment: true
  },
  
  // Enable validation
  validate: true,
  
  // Enable strict validation mode
  strictValidation: false,
  
  // Enable hot reload in dev mode
  watch: true,
  
  // Enable debug logging
  debug: false
})

Inline Configuration

firebaseConfig({
  source: 'inline',
  config: {
    apiKey: 'your-api-key',
    authDomain: 'your-domain.com',
    projectId: 'your-project-id',
    storageBucket: 'your-bucket.appspot.com',
    messagingSenderId: '123456789',
    appId: '1:123:web:abc'
  }
})

Environment-Specific Overrides

firebaseConfig({
  environments: {
    development: {
      authDomain: 'localhost:5173'
    },
    production: {
      authDomain: 'your-production-domain.com'
    }
  }
})

Custom Transform

firebaseConfig({
  transform: (config) => {
    // Modify config before writing
    if (process.env.NODE_ENV === 'development') {
      config.authDomain = 'localhost:5173'
    }
    return config
  }
})

Validation Modes

By default, the plugin uses non-strict validation mode (strictValidation: false), which shows warnings for missing configuration but allows the build to continue. This is useful during development when you might not have all configuration ready yet.

// Non-strict mode (default) - Shows warnings, allows build to continue
firebaseConfig({
  strictValidation: false  // Missing fields filled with empty strings
})

// Strict mode - Throws errors and stops build if configuration is invalid
firebaseConfig({
  strictValidation: true  // Recommended for production builds
})

Recommendation: Use strictValidation: false during development for flexibility, and strictValidation: true in production builds to ensure all configuration is properly set.

📖 API Reference

PluginOptions

| Option | Type | Default | Description | |--------|------|---------|-------------| | source | 'env' \| 'inline' | 'env' | Configuration source | | envPrefix | string | 'VITE_FIREBASE_' | Prefix for environment variables | | config | FirebaseConfig | undefined | Inline configuration object | | output.path | string | 'public/__/auth/init.json' | Output file path | | output.indent | number | 2 | JSON indentation | | output.addWarningComment | boolean | true | Add warning comment to file | | environments | Record<string, Partial<FirebaseConfig>> | {} | Environment-specific overrides | | validate | boolean | true | Validate configuration | | strictValidation | boolean | false | When false, shows warnings instead of errors for missing fields | | watch | boolean | true | Enable hot reload | | transform | (config) => config | undefined | Custom transform function | | debug | boolean | false | Enable debug logging |

Environment Variables

The plugin reads these environment variables (with default prefix VITE_FIREBASE_):

  • VITE_FIREBASE_API_KEYapiKey (required)
  • VITE_FIREBASE_AUTH_DOMAINauthDomain (required)
  • VITE_FIREBASE_PROJECT_IDprojectId (required)
  • VITE_FIREBASE_STORAGE_BUCKETstorageBucket (required)
  • VITE_FIREBASE_MESSAGING_SENDER_IDmessagingSenderId (required)
  • VITE_FIREBASE_APP_IDappId (required)
  • VITE_FIREBASE_MEASUREMENT_IDmeasurementId (optional)
  • VITE_FIREBASE_DATABASE_URLdatabaseURL (optional)

🧪 Examples

See the examples directory for complete working examples:

🤝 Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details.

📄 License

MIT © vite-plugin-firebase-config contributors

🙏 Credits

Created to solve Firebase Auth configuration issues in static hosting environments.

📚 Related