
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
nuxt-feature-flags
Advanced tools
A feature flag module for Nuxt 3 with context-aware evaluation and server-side support, inspired by @happykit/flags.
npx nuxi module add nuxt-feature-flags
// ~/feature-flags.context.ts
import { parseCookies } from 'h3'
import { detectDevice } from '~/utils/device'
export default function featureFlagsContext(event: any) {
return {
user: event?.context.user,
cookies: parseCookies(event),
device: detectDevice(event),
environment: process.env.NODE_ENV
}
}
nuxt.config.ts
:export default defineNuxtConfig({
modules: ['nuxt-feature-flags'],
featureFlags: {
contextPath: '~/feature-flags.context',
flags: {
experimentalFeature: (context) => context.user?.isBetaTester
},
defaultContext: {
environment: process.env.NODE_ENV
}
}
})
<script setup>
const { isEnabled, get } = useFeatureFlags()
</script>
<template>
<div>
<NewDashboard v-if="isEnabled('newDashboard')" />
<div v-if="get('experimentalFeature')?.explanation">
Flag reason: {{ get('experimentalFeature')?.explanation?.reason }}
</div>
</div>
</template>
interface ModuleOptions {
flags?: Record<string, FlagDefinition>
defaultContext?: Record<string, any>
envKey?: string
contextPath?: string
}
// nuxt.config.ts
export default defineNuxtConfig({
featureFlags: {
contextPath: '~/feature-flags.context',
flags: {
promoBanner: true,
userSurvey: { percentage: 50 },
betaFeature: (ctx) => ctx.user?.tier === 'premium'
},
defaultContext: {
environment: process.env.NODE_ENV
},
envKey: 'NUXT_PUBLIC_FEATURE_FLAGS'
}
})
Create a file at the specified contextPath
(default: ~/feature-flags.context.ts
) that exports a function:
export default function featureFlagsContext(event: any) {
return {
// Your context properties
}
}
The function receives the Nitro event and should return an object with the evaluation context.
const {
flags, // Reactive flags object
isEnabled, // (flagName: string) => boolean
get // <T>(flagName: string) => Flag<T> | undefined
} = useFeatureFlags()
type FlagDefinition =
| boolean
| ((context: EvaluationContext) => boolean)
Contributions are welcome! Please follow these steps for local development:
# Install dependencies
npm install
# Develop with playground
npm run dev
# Lint code
npm run lint
MIT License © 2025 Roberth González
FAQs
Feature flags for Nuxt
The npm package nuxt-feature-flags receives a total of 63 weekly downloads. As such, nuxt-feature-flags popularity was classified as not popular.
We found that nuxt-feature-flags demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.