A feature flag plugin for Vite.
-
Install the plugin.
pnpm add -D @virtual-live-lab/vite-plugin-feature-flags
-
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, }), ], });
-
Add type declaration for feature flags.
/// <reference types="@virtual-live-lab/vite-plugin-feature-flags/client" /> interface ImportMetaFeatures { hoge: boolean; fuga: boolean; }
-
Use feature flags in your code.
if (import.meta.features.hoge) { console.log("hoge is enabled"); }