Skip to content

Commit 9f2341b

Browse files
committed
docs: add docs about env variables
1 parent 23f144a commit 9f2341b

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.

0 commit comments

Comments
 (0)