I have a ReactJS App with below directory structure,
App/
- components
- - SubComponent1
- - - components
- - - - SubSubComponent1
- - - - - components
- - - - - ....
- - - - - SubSubCompoent1.js
- - - SubComponent1.js
- - SubComponent2
- - ...
- - SubComponent3
- - ...
- stores
- actions
- app.js
Module Components are designed such a way that all its subcomponent remained inside its own directory under components folder.
Also components has its own components which also reside components folder inside parent component folder.
Thus creates a relative import problem along with it gets messy with nesting so many levels.
If I make all components under root app components, then there will be lot of components and who is using which one will be a question.
So What I am asking is what will be the best directory structure for this kind of scenario?
SOVLED
In webpack config add this,
resolve: {
root: __dirname + PATH_TO_APP_ROOT
}
Now you can use require('dir/file.js')
instead of require('../../../../dir/file.js')
I use a structure similar to this:
Each component has it's own folder that contains it's assets (I use webpack to compile) and subcomponents are nested within their parent folders.