import statements in this codebase often use the convention of something like:
import rootReducer from '../reducers';
This works because there is a ../reducers/index.js file with an export default statement and webpack transcodes the import statement into a require statement and webpack supports the node standard of looking for an index.js file automatically.
However, this feels a little icky because, AFAICT, javascript modules and the import statement do not have any mechanism or spec for this kind of automatic finding of an index.js file.
Currently the only side effect of this that I can see or think of is that tooling that supports ES6 modules (like WebStorm and other IDEs), don't know WTF is up when they see these statements.
No one might care about this (I barely care enough to post this issue) so feel free to tell me to take a hike!
I'm happy to accept a PR fixing this across the code base.
@gaearon The easiest fix would be to just change import rootReducer from '../reducers' to import rootReducer from '../reducers/index'. But then I wonder what's the point of having a bunch of files named index.js? That's a problem when you've got multiple files open in your IDE and all the tabs say "index.js"...it's harder to see what you're working on or which tab you want to switch to.
I guess you could rename them to something like /reducers/reducers.js.
Any thoughts or preferences?
However, this feels a little icky because, AFAICT, javascript modules and the import statement do not have any mechanism or spec for this kind of automatic finding of an index.js file.
Whoa, I didn't know this. Good to know!
According to Airbnb React styleguide current notation is _preferable_, but i also have gone into trouble finding the right index.js in my editor too :sweat_smile:
Anyway /reducer/reducer.js looks obsolete.
FWIW, WebStorm's current EAP can find those index.js files just fine.
I'd say we leave it as is for now. Node resolve mechanism currently has index.js in its algorithm, and until we have something better, you should ask IDEs to fully support it.
Most helpful comment
I'd say we leave it as is for now. Node resolve mechanism currently has
index.jsin its algorithm, and until we have something better, you should ask IDEs to fully support it.