Offer a way to import files relative to `src/`
See original GitHub issueNot really sure about this, but I find it quite annoying to have imports that look like:
import mock from "../../../testUtils/myMock"
Relative paths are good for resources that will always live next to the calling file but when referring to shared helpers/modules I find them quite counter-productive.
It would be possible to configure webpack so we could import files from src/
just like import 'testUtils/myMock
or maybe src/testUtils/myMock
by adding src
to the resolve root.
Would it make sense ? Maybe relative paths are not that bad and I’m missing something ?
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (8 by maintainers)
Top Results From Across the Web
Ask Question - Stack Overflow
You should be able to import anything inside src without relative paths. Note I would not recommend calling your folder src/redux because ...
Read more >Absolute imports with Create React App | by David Gilbertson
I think it's reasonable to say that sibling files should be imported with a relative path, but not anything where you need to...
Read more >Why and How to Use Absolute Imports in React
Using absolute imports to better organize your React project is a great way. Relative imports are hard to follow and break during ...
Read more >Use Absolute Paths with React - Better Programming
By default, relative paths are the supported way of importing modules ... For instance, all modules that live inside src/components/ can now ...
Read more >Auto import | PyCharm Documentation - JetBrains
In the Settings/Preferences dialog ( Ctrl+Alt+S ), click Editor | General | Auto Import. · In the Python section, configure automatic imports:.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
NODE_PATH=./src
before every script command in package.jsonfrom 'entities/posts'
assumingentities
exists insidesrc
.I quite like the idea how Vue solved it in
vue-cli
: They configured webpack to replace@/
by the source directory usingresolve.alias
. I quite like the idea and typingimport "@/base/components/FooBar"
doesn’t look too bad.@
on its own should never be a validscope
and should be pretty future proof.How about adopting that idea to
create-react-app
as well?