{"id":13506694,"url":"https://github.com/stephenkr/nuxt-feature-toggle","last_synced_at":"2025-10-20T03:17:02.269Z","repository":{"id":40948777,"uuid":"187399856","full_name":"stephenkr/nuxt-feature-toggle","owner":"stephenkr","description":"The nuxt feature toggle module","archived":false,"fork":false,"pushed_at":"2023-03-07T08:10:26.000Z","size":2650,"stargazers_count":90,"open_issues_count":18,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-04T04:32:16.001Z","etag":null,"topics":["feature","nuxt","nuxt-module","nuxtjs","toggle","toggle-switches"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/nuxt-feature-toggle","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stephenkr.png","metadata":{"files":{"readme":"Readme.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-05-18T19:57:13.000Z","updated_at":"2024-05-30T16:20:00.000Z","dependencies_parsed_at":"2024-01-13T04:12:08.969Z","dependency_job_id":"f3dfbf8d-9ef4-465d-8c8b-66879506aade","html_url":"https://github.com/stephenkr/nuxt-feature-toggle","commit_stats":{"total_commits":71,"total_committers":7,"mean_commits":"10.142857142857142","dds":0.352112676056338,"last_synced_commit":"6ba93658d3b829c4f8fed2c08b0ac424314839ab"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenkr%2Fnuxt-feature-toggle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenkr%2Fnuxt-feature-toggle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenkr%2Fnuxt-feature-toggle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenkr%2Fnuxt-feature-toggle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stephenkr","download_url":"https://codeload.github.com/stephenkr/nuxt-feature-toggle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252928154,"owners_count":21826629,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["feature","nuxt","nuxt-module","nuxtjs","toggle","toggle-switches"],"created_at":"2024-08-01T01:00:55.603Z","updated_at":"2025-10-20T03:17:02.150Z","avatar_url":"https://github.com/stephenkr.png","language":"JavaScript","readme":"\u003ch1 align=\"center\"\u003enuxt-feature-toggle\u003c/h1\u003e\n\u003cp align=\"center\"\u003eThis is a simple module for Nuxt.js to add support for a feature toggle system.\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://david-dm.org/stephenkr/nuxt-feature-toggle\"\u003e\n    \u003cimg alt=\"\" src=\"https://david-dm.org/stephenkr/nuxt-feature-toggle/status.svg?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://standardjs.com\"\u003e\n    \u003cimg alt=\"\" src=\"https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/nuxt-feature-toggle\"\u003e\n    \u003cimg alt=\"\" src=\"https://img.shields.io/npm/v/nuxt-feature-toggle/latest.svg?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003cbr/\u003e\n  \u003ca href=\"https://www.npmjs.com/package/nuxt-feature-toggle\"\u003e\n    \u003cimg alt=\"\" src=\"https://img.shields.io/npm/dt/nuxt-feature-toggle.svg?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://circleci.com/gh/stephenkr/nuxt-feature-toggle\"\u003e\n    \u003cimg alt=\"\" src=\"https://img.shields.io/circleci/project/github/stephenkr/nuxt-feature-toggle.svg?style=flat-square\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"./CHANGELOG.md\"\u003eRelease notes\u003c/a\u003e\n\u003c/p\u003e\n\n## Features\n- Dynamically pull in your feature toggles when the application starts\n- Set a static list of feature toggles\n- Optional query string support to override a feature toggle\n\n## Usage\n\n### 1. Install the plugin\n\n```sh\nnpm install nuxt-feature-toggle\n# or\nyarn add nuxt-feature-toggle\n```\n\n\n### 2. Add module to nuxt.config.js along with the feature toggle options.\n\nThe toggles can be defined as a function or just as an object.\n\n#### As a function\n```javascript\nmodule.exports = {\n  modules: ['nuxt-feature-toggle'],\n\n  featureToggle: {\n    toggles: () =\u003e {\n      return Promise.resolve({\n        'my-unique-key': true\n      })\n    }\n  }\n}\n```\n\n#### As an object\n```javascript\nmodule.exports = {\n  modules: ['nuxt-feature-toggle'],\n\n  featureToggle: {\n    toggles: {\n      'my-unique-key': true\n    }\n  }\n}\n```\n\n### 2. Use the feature toggle component\n\n```html\n\u003cfeature-toggle name=\"my-unique-key\" :value=\"true\"\u003e\n  \u003cp\u003eThis can only show if the toggle is enabled\u003c/p\u003e\n\u003c/feature-toggle\u003e\n```\n\n## RuntimeConfig support\nIf using Nuxt \u003e= 2.13, you can use the new `publicRuntimeConfig` setting in `nuxt.config.js` to **configure\nfeature toggles on-the-fly without having to rebuild** (only need to restart Nuxt using `nuxt start`).\n\n```javascript\nmodule.exports = {\n  modules: ['nuxt-feature-toggle'],\n  publicRuntimeConfig: {\n    featureToggle:{\n      toggles: {\n        somePreviewFeature: process.env.FEATURE_ENABLE_SOME_PREVIEW_FEATURE,\n      }\n    }\n  }\n}\n```\n\u003e Note 1: `FEATURE_ENABLE_SOME_PREVIEW_FEATURE` is an arbitrary name, the package doesn't depend on it.\nYou can use \"Feature Flag\" names eg. `FF_PREVIEW_FEATURE` or whatever suits you.\n\n\u003e Note 2: This package has built-in [yn](https://github.com/sindresorhus/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`.\n\nNow you just need to change your environment variables an restart Nuxt to toggle your features!\n\n### Important note on `publicRuntimeConfig` and Promise / function based toggles\n**If you're using function/promise based toggles resolution, you should not use `publicRuntimeConfig`:**\nwhile it's technically *possible* to use a function in `runtimeConfig`, [it is not recommended](https://nuxtjs.org/guide/runtime-config/).\n\n**A function/promise based toggles resolution will NOT be resolved in the plugin, only on build.**\n\nInstead you should either:\n* Use a Promise/Function in `featureToggle.toggles` like you did before\n* Switch to object mode in `publicRuntimeConfig.featureToggle.toggles`.\n\nAs now you can use environment variables and just restart the server, many people can get rid of Promises returning toggles depending on the environment.\n\n\n## Use with the query string\n\nTo use the query string with your feature toggles, first enable it in your configuration file.\n\n```javascript\nmodule.exports = {\n  modules: ['nuxt-feature-toggle'],\n\n  featureToggle: {\n    queryString: true,\n    toggles: {\n      'my-unique-key': true\n    }\n  }\n}\n```\n\nThe 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.\n\n### Change key prefix\n\nTo change the default toggle prefix for `toggle`, you can now pass an option to change it to anything you like, such as:\n```html\n\u003cfeature-toggle name=\"my-unique-key\" :value=\"true\" prefix=\"_t\"\u003e\n  \u003cp\u003eThis can only show if the toggle is enabled\u003c/p\u003e\n\u003c/feature-toggle\u003e\n```\n\nIn this case, the key is now `_t_my-unique-key`\n\n### Allowing access\n\nYou can control the access of the query string using a function, this can be defined using the following approach.\n\n1. Create a new plugin file and import it into your nuxt.config.js file.\n\n2. Add the following code to your new plugin\n\n```javascript\nexport default function({ $featureToggle }) {\n  $featureToggle.isQueryStringAllowed(props =\u003e {\n    return true;\n  })\n}\n```\n\nHere you can access the props for the feature toggle component, and you can access the context using the exported function.\n\nIf no function is defined, and the `queryString` option is true, then all query strings are allowed.\n\n### Usage\n\nOnce 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.\n\n```\nhttps://website.com?toggle_my-unique-key=false\n```\n\nThis will set the feature toggle 'my-unique-key' to false when viewing the page.\n\n# To use the demo\n\n1. Go to the `examples/demo` folder\n2. Run the command `yarn`\n3. Once done, run `yarn dev`\n4. Navigate to `http://localhost:3000`\n\n## About the demo\n\nThe 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.\n\n![](./docs/assets/demo-1.gif)\n\n# License\n\n\u003ca href=\"./LICENSE\"\u003eMIT License\u003c/a\u003e\n","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephenkr%2Fnuxt-feature-toggle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstephenkr%2Fnuxt-feature-toggle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephenkr%2Fnuxt-feature-toggle/lists"}