Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 1.05 KB

File metadata and controls

49 lines (36 loc) · 1.05 KB

@virtual-live-lab/vite-plugin-feature-flags

npm)

A feature flag plugin for Vite.

How to use

  1. Install the plugin.

    pnpm add -D @virtual-live-lab/vite-plugin-feature-flags
  2. Add this plugin to vite.config.ts.

    import { defineConfig } from "vite";
    import { featuresPlugin } from "vite-plugin-feature-flags";
    
    export default defineConfig({
      plugins: [
        featuresPlugin({
          // your feature flags
          hoge: true,
          fuga: false,
        }),
      ],
    });
  3. Add type declaration for feature flags.

    /// <reference types="@virtual-live-lab/vite-plugin-feature-flags/client" />
    
    interface ImportMetaFeatures {
      hoge: boolean;
      fuga: boolean;
    }
  4. Use feature flags in your code.

    if (import.meta.features.hoge) {
      console.log("hoge is enabled");
    }