-
-
Save horacioh/5c0a88d3ae4d04ba2ed3313a8db73b11 to your computer and use it in GitHub Desktop.
Alias the `src` directory on create-react-app
This file contains hidden or 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
NODE_PATH=. |
This file contains hidden or 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
import React, { Component } from 'react'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
/* | |
with the `.env` file added, then you can use the src directory as an alias. no matter from where you are in your code, | |
you can avoid using `../../../../....` all over the place. Just use `import X from 'src/path/to/your/component' | |
------- ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ------------ | |
*/ | |
import Home from 'src/Home'; | |
class App extends Component { | |
render() { | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<img src={logo} className="App-logo" alt="logo" /> | |
<p> | |
Edit <code>src/App.js</code> and save to reload. | |
</p> | |
<Home /> | |
</header> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment