Skip to content

Add info on defining cross-platform env variables #8388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docusaurus/docs/using-https-in-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@ HTTPS=true npm start

Note that the server will use a self-signed certificate, so your web browser will almost definitely display a warning upon accessing the page.

To avoid having to set the environment variable each time, you can either include in the `npm start` script like so:
To avoid having to set the environment variable each time, you can include it in the `npm start` script like so:

```json
{
"start": "HTTPS=true react-scripts start"
}
```

Or you can create a `.env` file with `HTTPS=true` set.
However, this will only work on Linux and macOS (Bash), as Windows defines the environment variables differently. You can use [`cross-env`](https://www.npmjs.com/package/cross-env) to overcome this issue. The package provides a seamless way of defining cross-platform environment variables through the CLI. After installing `cross-env` through your favourite package manager, you can use it to include the environment variable in the `npm start` script like so:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thexpand thanks for the PR! How about keeping ### Linux, macOS (Bash) as-is, and adding a separate header ### Linux, Windows so that it's more clear at a glance?

cc @oluoluoxenfree

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amyrlam Yes, it makes sense. I'll separate it. Maybe the section can be named even better, like this: ### Cross-platform (Linux, Windows, macOS) - what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thexpand 👍 sounds good, thank you!


```json
{
"start": "cross-env HTTPS=true react-scripts start"
}
```

Alternatively, you can create a `.env` file with `HTTPS=true` set.
[Learn more about environment variables in CRA](https://create-react-app.dev/docs/adding-custom-environment-variables).