Skip to content

Instantly share code, notes, and snippets.

@aaccurso
Last active July 2, 2017 03:03
Show Gist options
  • Save aaccurso/38b9c3a6a5f62e74e221c04e752bf69f to your computer and use it in GitHub Desktop.
Save aaccurso/38b9c3a6a5f62e74e221c04e752bf69f to your computer and use it in GitHub Desktop.
Allow importing modules from the `src/` directory example.
// Location: src/components/deep/module/foo/Foo.js
import React, { Component} from 'react';
// We want to avoid importing modules relative to the current file
// import Bar from '../../../../bar/Bar.js';
// Instead we want to have a clearer way of importing modules relative to `src/`
import Bar from 'components/bar/Bar.js';
export default class Foo extends Component {
render() {
return (
<div>
Foo <Bar/>
</div>
);
}
}
// Location: src/components/bar/Bar.js
import React, { Component} from 'react';
export default class Bar extends Component {
render() {
return <span>Bar</span>;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment