Skip to content
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

Absolute path guide #1712

Closed
wants to merge 3 commits into from
Closed
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
29 changes: 29 additions & 0 deletions packages/react-scripts/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,35 @@ Learn more about ES6 modules:
* [Exploring ES6: Modules](http://exploringjs.com/es6/ch_modules.html)
* [Understanding ES6: Modules](https://leanpub.com/understandinges6/read#leanpub-auto-encapsulating-code-with-modules)

## Importing a Component using path relative to src (Absolute path)

**NOTE**: Make sure to remove `.env` from your .gitignore in the project root

Create a file called `.env` in the root of the project, then add the following:

```
NODE_PATH=src
```

This will allows any component to be imported using its path relative to `src`, for example:

```js
import Button from './components/Button';
```

is now:


```js
import Button from 'components/Button';
```

This allows uniform import path accross different component, and eliminate the following "hypothetical" situation:

```js
import Utils from '../../../Utils';
```

## Code Splitting

Instead of downloading the entire app before users can use it, code splitting allows you to split your code into small chunks which you can then load on demand.
Expand Down