A small library that provides a simple way to define and read feature flags in a Webiny project.
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;
// 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:
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, thefeatureFlags
object can be accessed within both backend and frontend application code.
No additional examples.
Type Declaration
declare let featureFlags: Record<string, any>;
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.
import { featureFlags } from "@webiny/feature-flags";
const useMyCustomFeature = featureFlags.myCustomFeatureFlag;
const someOtherFeatureMyCustomProperty = featureFlags.someFeature.myCustomProperty;