1 | # Features
|
2 |
|
3 | [RFC](https://github.com/salesforce/lwc-rfcs/blob/master/text/0111-feature-flags.md)
|
4 |
|
5 | ## Compile-time flags
|
6 |
|
7 | ## Runtime flags
|
8 |
|
9 | Runtime flags can be enabled or disabled by setting a boolean value for that
|
10 | flag in `globalThis.LWC_config.features`. If the flag is not explicitly
|
11 | configured, the feature is disabled by default. This configuration object
|
12 | must appear before `@lwc/engine` is initialized and should be defined at the
|
13 | application layer.
|
14 |
|
15 | ### Limitations
|
16 |
|
17 | #### Must be all uppercase
|
18 |
|
19 | ```
|
20 | // Does not work
|
21 | if (enableFoo) {
|
22 | ...
|
23 | }
|
24 |
|
25 | // Does work
|
26 | if (ENABLE_FOO) {
|
27 | ...
|
28 | }
|
29 | ```
|
30 |
|
31 | #### Only works with if-statements
|
32 |
|
33 | ```
|
34 | // Does not work
|
35 | const foo = ENABLE_FOO ? 1 : 2;
|
36 |
|
37 | // Does work
|
38 | let foo;
|
39 | if (ENABLE_FOO) {
|
40 | foo = 1;
|
41 | } else {
|
42 | foo = 2;
|
43 | }
|
44 | ```
|
45 |
|
46 | #### Only works with identifiers
|
47 |
|
48 | ```
|
49 | // Does not work
|
50 | if (isTrue(ENABLE_AWESOME_FEATURE)) {
|
51 | // awesome feature
|
52 | }
|
53 |
|
54 | // Does work
|
55 | if (ENABLE_AWESOME_FEATURE) {
|
56 | // awesome feature
|
57 | }
|
58 | ```
|
59 |
|
60 | #### Initialization code cannot be tested
|
61 |
|
62 | Toggling the value of `ENABLE_FOO` during a test will not change the return
|
63 | value of `getFooValue`.
|
64 |
|
65 | ```
|
66 | import { ENABLE_FOO } from '@lwc/features';
|
67 |
|
68 | let foo;
|
69 | if (ENABLE_FOO) {
|
70 | foo = 1;
|
71 | } else {
|
72 | foo = 2;
|
73 | }
|
74 |
|
75 | function getFooValue() {
|
76 | return foo;
|
77 | }
|
78 | ```
|