Skip to content

Instantly share code, notes, and snippets.

@horacioh
Created January 17, 2019 09:39
Show Gist options
  • Save horacioh/5c0a88d3ae4d04ba2ed3313a8db73b11 to your computer and use it in GitHub Desktop.
Save horacioh/5c0a88d3ae4d04ba2ed3313a8db73b11 to your computer and use it in GitHub Desktop.
Alias the `src` directory on create-react-app
NODE_PATH=.
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