Nuxt.js module to use Flagsmith toggle feature services
npm install nuxt-flagsmith[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Github Actions CI][github-actions-ci-src]][github-actions-ci-href]
[![Codecov][codecov-src]][codecov-href]
[![License][license-src]][license-href]
> Nuxt.js module to use Flagsmith toggle feature services
> Inspired from conejerock's nuxt-unleash.
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.
1. Add nuxt-flagsmith dependency to your project
``bash`
yarn add nuxt-flagsmith
2. Add nuxt-flagsmith to the modules section of nuxt.config.js
`js
export default {
modules: [
// Simple usage
'nuxt-flagsmith',
// With options
[
'nuxt-flagsmith',
{
/ module options /
},
],
],
}
`
:warning: 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.
`js`
export default {
buildModules: ['nuxt-flagsmith'],
flagsmith: {
/ module options /
},
}
- Type: Stringfalse
- Required: https://api.flagsmith.com
- Default:
Flagsmith API URL
- Type: Stringtrue
- Required:
Flagsmith API Environment ID
#### Client Side
To access the module in side client you just have to call this.$flagsmith and method you want to use.
`js
{{ value ? 'enabled' : 'disabled' }}
`
#### Sever Side
To access the module in side server you just have to call ctx.app.flagsmith and method you want to use.
`js`
asyncData(ctx) {
const value = ctx.app.flagsmith.isEnabled('new-feature')
if(value) {
ctx.redirect('/new-feature-page')
}
}
The library provides four methods:
#### isEnabled
If the feature flag exists, return its status value. Otherwise, return the value of module option enabledDefault.
`js`
this.$flagsmith.isEnabled('new-feature')
1. Clone this repository
2. Install dependencies using yarn install or npm installnpm run dev`
3. Start development server using
Copyright (c) mstfymrtc
[npm-version-src]: https://img.shields.io/npm/v/nuxt-flagsmith/latest.svg
[npm-version-href]: https://npmjs.com/package/nuxt-flagsmith
[npm-downloads-src]: https://img.shields.io/npm/dt/nuxt-flagsmith.svg
[npm-downloads-href]: https://npmjs.com/package/nuxt-flagsmith
[github-actions-ci-src]: https://github.com/mstfymrtc/nuxt-flagsmith/workflows/ci/badge.svg
[github-actions-ci-href]: https://github.com/mstfymrtc/nuxt-flagsmith/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/github/mstfymrtc/nuxt-flagsmith.svg
[codecov-href]: https://codecov.io/gh/mstfymrtc/nuxt-flagsmith
[license-src]: https://img.shields.io/npm/l/nuxt-flagsmith.svg
[license-href]: https://npmjs.com/package/nuxt-flagsmith