Skip to content

External Feature Flags Config File #79

@nicokempe

Description

@nicokempe

What problem does this feature solve?

Allow projects to load feature flags from an external config file instead of keeping them inline in nuxt.config.ts. This improves maintainability, supports reuse across projects, and keeps nuxt.config.ts clean.

Usage

In nuxt.config.ts

export default defineNuxtConfig({
  modules: ['nuxt-feature-flags-module'],
  featureFlags: {
    configFile: './feature-flags.config.ts',
    mergeStrategy: 'merge', // optional: 'merge' (default) | 'replace'
  }
})

In feature-flags.config.ts

import { defineFeatureFlags } from 'nuxt-feature-flags-module/helpers'

export default defineFeatureFlags({
  environment: 'staging',
  flagSets: {
    development: ['solutions/*'],
    staging: ['solutions/company-portal/*'],
    production: ['solutions/company-portal/addons/sales'],
  },
  validation: {
    mode: 'warn',
  },
})

Behavior

  • configFile → path to external config file (relative to project root).
  • mergeStrategy
    • merge (default): combine external + inline flags (inline wins on conflicts).
    • replace: ignore inline flags, use only external config.
  • External config must default export an object created with defineFeatureFlags().
  • Dev mode: file changes are watched and re-validated automatically.

Benefits

  • Keeps nuxt.config.ts clean.
  • Easier to maintain hundreds of flags.
  • Share one flags file across multiple apps.
  • Fully type-safe with defineFeatureFlags().

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions