nuxt-flagsmith
Nuxt.js module to use Flagsmith toggle feature services
Inspired from conejerock's nuxt-unleash.
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
- Add
nuxt-flagsmith
dependency to your project
yarn add nuxt-flagsmith
- Add
nuxt-flagsmith
to themodules
section ofnuxt.config.js
export default {
modules: [
// Simple usage
'nuxt-flagsmith',
// With options
[
'nuxt-flagsmith',
{
/* module options */
},
],
],
}
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
- Clone this repository
- Install dependencies using
yarn install
ornpm install
- Start development server using
npm run dev
License
Copyright (c) mstfymrtc