File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ title : Adding custom env variables
3+ order : 3
4+ shortTitle : ENV Variables
5+ ---
6+
7+ Starting version ` 6.0.0 ` ` @wpackio/scripts ` can handle custom env variables from
8+
9+ - ` .env ` file at the root of your project.
10+ - Anything in ` process.env ` available during ` yarn start ` or ` yarn build ` .
11+
12+ All variables starting with ` WPAKCIO_ ` will be available in your application
13+ code without the ` WPACKIO_ ` prefix. So if you have ` WPACKIO_SECRET_KEY ` in your
14+ env, then you can access it from your app by ` process.env.SECRET_KEY ` .
15+
16+ ### Easiest way to get started
17+
18+ Start by creating a ` .env ` (note the leading dot) file at the root of your
19+ project. Now paste the following content in it
20+
21+ ``` text
22+ WPACKIO_STRIPE_PUBLIC_KEY="some-super-secret-key"
23+ WPACKIO_SENDY_PUBLIC_KEY="some-super-secret-key"
24+ ```
25+
26+ The above values would be available through ` process.env.STRIPE_PUBLIC_KEY `
27+ and ` process.env.SENDY_PUBLIC_KEY ` . The prefix ` WPACKIO_ ` is automatically
28+ stripped in application code.
29+
30+ ``` js
31+ const stripeSdk = Stripe (process .env .STRIPE_PUBLIC_KEY );
32+ const elements = stripeSdk .elements ();
33+ ```
34+
35+ > Anything in the ` env ` which does not start with ` WPACKIO_ ` is ignored. This is
36+ > made this way to prevent leaking sensitive credentials to the app.
You can’t perform that action at this time.
0 commit comments