You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Readme.md
+22-14Lines changed: 22 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,16 @@
31
31
32
32
## Usage
33
33
34
-
### 1. Add module to nuxt.config.js along with the feature toggle options.
34
+
### 1. Install the plugin
35
+
36
+
```sh
37
+
npm install nuxt-feature-toggle
38
+
# or
39
+
yarn add nuxt-feature-toggle
40
+
```
41
+
42
+
43
+
### 2. Add module to nuxt.config.js along with the feature toggle options.
35
44
36
45
The toggles can be defined as a function or just as an object.
37
46
@@ -72,8 +81,8 @@ module.exports = {
72
81
```
73
82
74
83
## RuntimeConfig support
75
-
If using Nuxt >= 2.13, you can use the new `publicRuntimeConfig` setting in `nuxt.config.js` to **configure
76
-
feature toggles on-the-fly without having to rebuild** (only need to restart Nuxt using `nuxt start`).
84
+
If using Nuxt >= 2.13, you can use the new `publicRuntimeConfig` setting in `nuxt.config.js` to **configure
85
+
feature toggles on-the-fly without having to rebuild** (only need to restart Nuxt using `nuxt start`).
77
86
78
87
```javascript
79
88
module.exports= {
@@ -87,24 +96,23 @@ module.exports = {
87
96
}
88
97
}
89
98
```
90
-
Note 1: `FEATURE_ENABLE_SOME_PREVIEW_FEATURE` is an arbitrary name, the package doesn't depend on it.
91
-
You can use "Feature Flag" names eg. `FF_PREVIEW_FEATURE` or whatever suits you.
99
+
> Note 1: `FEATURE_ENABLE_SOME_PREVIEW_FEATURE` is an arbitrary name, the package doesn't depend on it.
100
+
You can use "Feature Flag" names eg. `FF_PREVIEW_FEATURE` or whatever suits you.
92
101
93
-
Note 2: If you want to use `0/1` or `"true/false"` strings to enable/disable your features,
94
-
[check out this great package which makes it much easier.](https://github.com/sindresorhus/yn)
102
+
> 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`.
95
103
96
104
Now you just need to change your environment variables an restart Nuxt to toggle your features!
97
105
98
-
### Important note on `publicRuntimeConfig` and Promise / function based toggles
106
+
### Important note on `publicRuntimeConfig` and Promise / function based toggles
99
107
**If you're using function/promise based toggles resolution, you should not use `publicRuntimeConfig`:**
100
-
while it's technically *possible* to use a function in `runtimeConfig`, [it is not recommended](https://nuxtjs.org/guide/runtime-config/).
108
+
while it's technically *possible* to use a function in `runtimeConfig`, [it is not recommended](https://nuxtjs.org/guide/runtime-config/).
109
+
110
+
**A function/promise based toggles resolution will NOT be resolved in the plugin, only on build.**
101
111
102
-
**A function/promise based toggles resolution will NOT be resolved in the plugin, only on build.**
112
+
Instead you should either:
113
+
* Use a Promise/Function in `featureToggle.toggles` like you did before
114
+
* Switch to object mode in `publicRuntimeConfig.featureToggle.toggles`.
103
115
104
-
Instead you should either:
105
-
* Use a Promise/Function in `featureToggle.toggles` like you did before
106
-
* Switch to object mode in `publicRuntimeConfig.featureToggle.toggles`.
107
-
108
116
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.
0 commit comments