forked from facebook/create-react-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix facebook#2223 - [feature] Implement dotenv-expand to accept varia…
…ble expa… (facebook#3387) * fix facebook#2223 - [feature] Implement dotenv-expand to accept variable expansion in dot env files * add to README TOC * fix readme * Update README.md
- Loading branch information
Showing
8 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
REACT_APP_X = x-from-original-env | ||
REACT_APP_ORIGINAL_1 = from-original-env-1 | ||
REACT_APP_ORIGINAL_2 = from-original-env-2 | ||
REACT_APP_BASIC = basic | ||
REACT_APP_BASIC_EXPAND = ${REACT_APP_BASIC} | ||
REACT_APP_BASIC_EXPAND_SIMPLE = $REACT_APP_BASIC | ||
REACT_APP_EXPAND_EXISTING = $REACT_APP_SHELL_ENV_MESSAGE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/react-scripts/fixtures/kitchensink/src/features/env/ExpandEnvVariables.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
export default () => ( | ||
<span> | ||
<span id="feature-expand-env-1">{process.env.REACT_APP_BASIC}</span> | ||
<span id="feature-expand-env-2">{process.env.REACT_APP_BASIC_EXPAND}</span> | ||
<span id="feature-expand-env-3"> | ||
{process.env.REACT_APP_BASIC_EXPAND_SIMPLE} | ||
</span> | ||
<span id="feature-expand-env-existing"> | ||
{process.env.REACT_APP_EXPAND_EXISTING} | ||
</span> | ||
</span> | ||
); |
17 changes: 17 additions & 0 deletions
17
packages/react-scripts/fixtures/kitchensink/src/features/env/ExpandEnvVariables.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import ExpandEnvVariables from './ExpandEnvVariables'; | ||
|
||
describe('expand .env variables', () => { | ||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
ReactDOM.render(<ExpandEnvVariables />, div); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -978,6 +978,25 @@ Please refer to the [dotenv documentation](https://github.com/motdotla/dotenv) f | |
>Note: If you are defining environment variables for development, your CI and/or hosting platform will most likely need | ||
these defined as well. Consult their documentation how to do this. For example, see the documentation for [Travis CI](https://docs.travis-ci.com/user/environment-variables/) or [Heroku](https://devcenter.heroku.com/articles/config-vars). | ||
|
||
#### Expanding Environment Variables In `.env` | ||
|
||
>Note: this feature is available with `[email protected]` and higher. | ||
Expand variables already on your machine for use in your .env file (using [dotenv-expand](https://github.com/motdotla/dotenv-expand)). See [#2223](https://github.com/facebookincubator/create-react-app/issues/2223). | ||
|
||
For example, to get the environment variable `npm_package_version`: | ||
``` | ||
REACT_APP_VERSION=$npm_package_version | ||
# also works: | ||
# REACT_APP_VERSION=${npm_package_version} | ||
``` | ||
Or expand variables local to the current `.env` file: | ||
``` | ||
DOMAIN=www.example.com | ||
REACT_APP_FOO=$DOMAIN/foo | ||
REACT_APP_BAR=$DOMAIN/bar | ||
``` | ||
|
||
## Can I Use Decorators? | ||
|
||
Many popular libraries use [decorators](https://medium.com/google-developers/exploring-es7-decorators-76ecb65fb841) in their documentation.<br> | ||
|