Create-react-app: Support for absolute import

Created on 29 Jul 2016  ·  3Comments  ·  Source: facebook/create-react-app

For example, I have the following structure

+ src
|--img
|   |-- logo.svg
|
|--containers
|   |-- App.js

Instead of doing
import logo from "../img/logo.svg"
inside App.js it will be nice to do
import logo from "img/logo.svg"

and it will be easier to read if I have a component placed in deep directory like components/Sidebar/index.js.

Most helpful comment

Well, but you might still need to import a component from a different component:

// src/containers/NavBar/Navbar.js

import NavItem from 'components/NavItem';

is a lot nicer than

// src/containers/NavBar/Navbar.js

import NavItem from '../components/NavItem';

It gets even worse if you're following a nested, route-hirarchic structure.

All 3 comments

Good idea! We're having a discussion about this in #253!

What is the reason behind top-level “file type” folders? Seems like this is exactly why you want to group assets by component instead, e.g.

  components
    Logo
      Logo.js
      Logo.css
      logo.svg

Well, but you might still need to import a component from a different component:

// src/containers/NavBar/Navbar.js

import NavItem from 'components/NavItem';

is a lot nicer than

// src/containers/NavBar/Navbar.js

import NavItem from '../components/NavItem';

It gets even worse if you're following a nested, route-hirarchic structure.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dualcnhq picture dualcnhq  ·  3Comments

Evan-GK picture Evan-GK  ·  3Comments

stopachka picture stopachka  ·  3Comments

wereHamster picture wereHamster  ·  3Comments

jnachtigall picture jnachtigall  ·  3Comments