nuxt-flagsmith
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

nuxt-flagsmith

npm version npm downloads Github Actions CI Codecov License

Nuxt.js module to use Flagsmith toggle feature services

Inspired from conejerock's nuxt-unleash.

📖 Release Notes

Features

Use $flagsmith to access and handle your Flagsmith feature flags in client side, or context.app.flagsmith to access Flagsmith feature flags from server side.

Setup

  1. Add nuxt-flagsmith dependency to your project
yarn add nuxt-flagsmith
  1. Add nuxt-flagsmith to the modules section of nuxt.config.js
export default {
  modules: [
    // Simple usage
    'nuxt-flagsmith',

    // With options
    [
      'nuxt-flagsmith',
      {
        /* module options */
      },
    ],
  ],
}

⚠️ If you are using Nuxt < v2.9 you have to install the module as a dependency (No --dev or --save-dev flags) and use modules section in nuxt.config.js instead of buildModules.

Using top level options

export default {
  buildModules: ['nuxt-flagsmith'],
  flagsmith: {
    /* module options */
  },
}

Options

host

  • Type: String
  • Required: false
  • Default: https://api.flagsmith.com

Flagsmith API URL

environmentId

  • Type: String
  • Required: true

Flagsmith API Environment ID

Usage

Client Side

To access the module in side client you just have to call this.$flagsmith and method you want to use.

<template>
  <h1>{{ value ? 'enabled' : 'disabled' }}</h1>
</template>

<script>
export default {
  mounted() {
    this.value = this.$flagsmith.isEnabled('new-feature')
  }
}
</script>

Sever Side

To access the module in side server you just have to call ctx.app.flagsmith and method you want to use.

asyncData(ctx) {
  const value = ctx.app.flagsmith.isEnabled('new-feature')
  if(value) {
      ctx.redirect('/new-feature-page')
  }
}

Methods

The library provides four methods:

isEnabled

If the feature flag exists, return its status value. Otherwise, return the value of module option enabledDefault.

this.$flagsmith.isEnabled('new-feature')

Development

  1. Clone this repository
  2. Install dependencies using yarn install or npm install
  3. Start development server using npm run dev

License

MIT License

Copyright (c) mstfymrtc

Package Sidebar

Install

npm i nuxt-flagsmith

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

10.2 kB

Total Files

8

Last publish

Collaborators

  • mstfymrtc