A small library that provides a simple way to define and read feature flags in a Webiny project.
npm install @webiny/feature-flags@webiny/feature-flagsA small library that provides a simple way to define and read feature flags in a Webiny project.
- Installation
- Overview
- Examples
- Reference
- Objects
- featureFlags
```
npm install --save @webiny/feature-flags
Or if you prefer yarn:
``
yarn add @webiny/feature-flags
The @webiny/feature-flags exports a single featureFlags object which contains all of the feature flags initially set via the Webiny project's webiny.project.ts config file, via its featureFlags property.
For example, given the following webiny.project.ts config file;
`ts`
// webiny.project.ts
export default {
name: "webiny-js",
cli: {
...
},
// Feature flags are defined via a simple JavaScript object.
featureFlags: {
myCustomFeatureFlag: false,
someFeature: { enabled: true, myCustomProperty: 123, thisIsJson: "yes"}
}
};
Within both backend and frontend application code, the featureFlags object can then be read like so:
`ts
import { featureFlags } from "@webiny/feature-flags";
const useMyCustomFeature = featureFlags.myCustomFeatureFlag;
const someOtherFeatureMyCustomProperty = featureFlags.someFeature.myCustomProperty;
`
> NOTE
>
> Behind the scenes, it's the Webiny CLI that enables the propagation of the featureFlags object into the actual applications. As mentioned, the featureFlags object can be accessed within both backend and frontend application code.
No additional examples.
#### featureFlags
`Type Declaration
ts`
declare let featureFlags: Record
The featureFlags object contains all of the feature flags initially set via the Webiny project's webiny.project.ts config file, via its featureFlags property.
`ts
import { featureFlags } from "@webiny/feature-flags";
const useMyCustomFeature = featureFlags.myCustomFeatureFlag;
const someOtherFeatureMyCustomProperty = featureFlags.someFeature.myCustomProperty;
``