In your src folder you should have the structure similar to this:
src
└ scenes
├ components
│ ├ ComponentA
│ │ └ ComponentA.jsx
│ └ ComponentB
│ └ ComponentB.jsx
└ main
├ components
│ └ App
│ ├ components
│ │ ├ ComponentC
│ │ │ └ ComponentC.jsx
│ │ └ ComponentD
│ │ └ ComponentD.jsx
│ └ App.jsx
└ index.jsx
In your webpack.config.js you should have the following (Webpack 3):
const DirectoryNamedWebpackPlugin = require('directory-named-webpack-plugin');
...
let config = {
...
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: 'babel-loader'
}
]
},
resolve: {
modules: ['components', 'node_modules'],
extensions: ['.js', '.jsx'],
plugins: [
new DirectoryNamedWebpackPlugin(true)
]
}
...
}
modules.exports = config;
As a result of using the above configuration and folder structure webpack will search for components in components folders recursively in the same way it searches for Node modules in node_modules folder and you can include components by their names.
E. g. in src/scenes/main/index.jsx you can simply write:
import App from 'App';
in src/scenes/main/components/App/App.jsx you can write:
import ComponentC from 'ComponentC';
import ComponentD from 'ComponentD';
and in src/scenes/main/components/App/components/CompoentC/ComponentC.jsx you can write:
import ComponentA from 'ComponentA';
import ComponentB from 'ComponentB';
P. S.
I use the plugin directory-named-webpack-plugin to allow webpack to recognize files named after their parent folders as default entry points for components so in my IDE tabs' names I would not see ComponentA/index.jsx, ComponentB/index.jsx and instead see ComponentA.jsx, ComponentB.jsx.
index.jsfile in every directory which exports a set of components from it's own folder. Create aliases to these indexes and it's pretty slick.