A lightweight feature flag module for Nuxt 3, enabling dynamic feature toggling with multiple storage backends.
✅ Works in Client-Side & Server-Side
✅ Supports local, API, or Firebase as storage
✅ Optimized for performance (caching enabled)
✅ Role-based flags for user-specific features
✅ TypeScript support
✅ Seamless Pinia integration
npm install nuxt-feature-flag
Add the module to nuxt.config.ts
:
export default defineNuxtConfig({
modules: ['nuxt-feature-flag'],
featureFlags: {
storage: 'api', // Options: 'local', 'api'
apiUrl: 'https://your-backend.com/flags', // API for fetching feature flags
cache: true
}
});
<script setup lang="ts">
import { useFeatureFlag } from '#imports';
const isNewFeatureEnabled = useFeatureFlag('new_dashboard');
</script>
<template>
<div>
<h1>Welcome to our App</h1>
<NewFeature v-if="isNewFeatureEnabled" />
<OldFeature v-else />
</div>
</template>
export default defineEventHandler((event) => {
const isFeatureEnabled = useFeatureFlag('beta_feature');
if (!isFeatureEnabled) {
return { error: 'Feature disabled' };
}
return { success: 'Feature available' };
});
import { defineEventHandler } from 'h3';
import type { FeatureFlagOptions } from '#imports';
export default defineEventHandler(async () => {
const config = useRuntimeConfig();
const featureFlags: FeatureFlagOptions = config.public.featureFlags as FeatureFlagOptions;
if (featureFlags.storage === 'api' && featureFlags.apiUrl) {
return await $fetch(featureFlags.apiUrl);
}
return {
new_dashboard: true,
beta_feature: false,
};
});
- Role-Based Feature Flags
Extend to conditionally enable features per user role. - Pinia Store Integration
Store feature flags globally. - Cache Optimization
Store API responses in Redis or local storage.
- Fork the repository
- Create a feature branch (
feat/your-feature
) - Submit a pull request
MIT License.
This module provides a powerful, flexible, and high-performance feature flag system for Nuxt 3. 🚀
Need more features? Open an issue! 😊