All Projects → stephenkr → nuxt-feature-toggle

stephenkr / nuxt-feature-toggle

Licence: MIT License
The nuxt feature toggle module

Programming Languages

javascript
184084 projects - #8 most used programming language
Vue
7211 projects

Projects that are alternatives of or similar to nuxt-feature-toggle

nuxt-winston-log
Nuxt module for logging SSR errors using winston
Stars: ✭ 41 (-47.44%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-mail
Adds email sending capability to a Nuxt.js app. Adds a server route, an injected variable, and uses nodemailer to send emails.
Stars: ✭ 62 (-20.51%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-humans-txt
🧑🏻👩🏻 "We are people, not machines" - An initiative to know the creators of a website. Contains the information about humans to the web building - A Nuxt Module to statically integrate and generate a humans.txt author file - Based on the HumansTxt Project.
Stars: ✭ 27 (-65.38%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-speedkit
nuxt-speedkit will help you to improve the lighthouse performance score (100/100) of your website.
Stars: ✭ 401 (+414.1%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
date-fns-module
Modern JavaScript date utility library - date-fns for Nuxt.js
Stars: ✭ 68 (-12.82%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-ghost
Easy Ghost content API integration with Nuxt.js.
Stars: ✭ 27 (-65.38%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-stripejs
💳 NuxtJS module for Stripe.js which loads only when required and w/ retry mechanism
Stars: ✭ 17 (-78.21%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-ts-module
A tiny module to use Typescript within Nuxt.js application.
Stars: ✭ 21 (-73.08%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-prune-html
🔌⚡ Nuxt module to prune html before sending it to the browser (it removes elements matching CSS selector(s)), useful for boosting performance showing a different HTML for bots/audits by removing all the scripts with dynamic rendering
Stars: ✭ 69 (-11.54%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-stencil
Easy Stencil.js component library integration with Nuxt.js.
Stars: ✭ 16 (-79.49%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
applicationinsights-module
Application Insights module for NuxtJS
Stars: ✭ 14 (-82.05%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
separate-env-module
Tear your variables apart!
Stars: ✭ 53 (-32.05%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-quasar
Nuxt module for the Quasar Framework
Stars: ✭ 36 (-53.85%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-modules
AX2's Nuxt modules
Stars: ✭ 30 (-61.54%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
lumen-cms
GraphQL API-First CMS based on NodeJS and Vue 2, Nuxt and Vuetify
Stars: ✭ 77 (-1.28%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
supabase
An easy way to integrate Supabase with NuxtJS
Stars: ✭ 39 (-50%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-typo3
TYPO3 Frontend rendered in Vue.js and Nuxt (frontend for EXT:headless)
Stars: ✭ 66 (-15.38%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
vue-plausible
Plausible Analytics Vue.js Plugin and NuxtJS Module
Stars: ✭ 107 (+37.18%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-jsonld
A Nuxt.js module to manage JSON-LD in Vue component.
Stars: ✭ 198 (+153.85%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
yamlful
YAML-based HTTP client code generation
Stars: ✭ 77 (-1.28%)
Mutual labels:  nuxt, nuxtjs, nuxt-module

nuxt-feature-toggle

This is a simple module for Nuxt.js to add support for a feature toggle system.


Release notes

Features

  • Dynamically pull in your feature toggles when the application starts
  • Set a static list of feature toggles
  • Optional query string support to override a feature toggle

Usage

1. Install the plugin

npm install nuxt-feature-toggle
# or
yarn add nuxt-feature-toggle

2. Add module to nuxt.config.js along with the feature toggle options.

The toggles can be defined as a function or just as an object.

As a function

module.exports = {
  modules: ['nuxt-feature-toggle'],

  featureToggle: {
    toggles: () => {
      return Promise.resolve({
        'my-unique-key': true
      })
    }
  }
}

As an object

module.exports = {
  modules: ['nuxt-feature-toggle'],

  featureToggle: {
    toggles: {
      'my-unique-key': true
    }
  }
}

2. Use the feature toggle component

<feature-toggle name="my-unique-key" :value="true">
  <p>This can only show if the toggle is enabled</p>
</feature-toggle>

RuntimeConfig support

If using Nuxt >= 2.13, you can use the new publicRuntimeConfig setting in nuxt.config.js to configure feature toggles on-the-fly without having to rebuild (only need to restart Nuxt using nuxt start).

module.exports = {
  modules: ['nuxt-feature-toggle'],
  publicRuntimeConfig: {
    featureToggle:{
      toggles: {
        somePreviewFeature: process.env.FEATURE_ENABLE_SOME_PREVIEW_FEATURE,
      }
    }
  }
}

Note 1: FEATURE_ENABLE_SOME_PREVIEW_FEATURE is an arbitrary name, the package doesn't depend on it. You can use "Feature Flag" names eg. FF_PREVIEW_FEATURE or whatever suits you.

Note 2: This package has built-in yn support which mean you don't have to do anything to get your env variable as Boolean value. You can also use 0/1, y/n or any other value supported by the package. This will also work when queryString is set to true.

Now you just need to change your environment variables an restart Nuxt to toggle your features!

Important note on publicRuntimeConfig and Promise / function based toggles

If you're using function/promise based toggles resolution, you should not use publicRuntimeConfig: while it's technically possible to use a function in runtimeConfig, it is not recommended.

A function/promise based toggles resolution will NOT be resolved in the plugin, only on build.

Instead you should either:

  • Use a Promise/Function in featureToggle.toggles like you did before
  • Switch to object mode in publicRuntimeConfig.featureToggle.toggles.

As now you can use environment variables and just restart the server, many people can get rid of Promises returning toggles depending on the environment.

Use with the query string

To use the query string with your feature toggles, first enable it in your configuration file.

module.exports = {
  modules: ['nuxt-feature-toggle'],

  featureToggle: {
    queryString: true,
    toggles: {
      'my-unique-key': true
    }
  }
}

The option queryString is used to enable query string support, so if the url contains a toggle query string, then the feature toggles with the matching value will be forced to show.

Change key prefix

To change the default toggle prefix for toggle, you can now pass an option to change it to anything you like, such as:

<feature-toggle name="my-unique-key" :value="true" prefix="_t">
  <p>This can only show if the toggle is enabled</p>
</feature-toggle>

In this case, the key is now _t_my-unique-key

Allowing access

You can control the access of the query string using a function, this can be defined using the following approach.

  1. Create a new plugin file and import it into your nuxt.config.js file.

  2. Add the following code to your new plugin

export default function({ $featureToggle }) {
  $featureToggle.isQueryStringAllowed(props => {
    return true;
  })
}

Here you can access the props for the feature toggle component, and you can access the context using the exported function.

If no function is defined, and the queryString option is true, then all query strings are allowed.

Usage

Once the querystring options are setup, you can enter the following to change the feature toggle, ensure toggle_ is prefixed to the name of the feature toggle.

https://website.com?toggle_my-unique-key=false

This will set the feature toggle 'my-unique-key' to false when viewing the page.

To use the demo

  1. Go to the examples/demo folder
  2. Run the command yarn
  3. Once done, run yarn dev
  4. Navigate to http://localhost:3000

About the demo

The demo will show how the query string functionality works with the feature toggles. You should see a control box on the left hand side where you can manipulate the query strings in the URL. This will update the feature toggle on the page.

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].