Using Webpack , how can you configure the loader to get the file through the import using the path

import User from 'elements/user'; 

the structure of the project itself looks like this

 elements/user/user.js 

user.js needs to be taken automatically based on the same folder name (analogous to the work of the default index.js file ). That is, the folder and file must be the same. If someone has a good solution help pliz.

    1 answer 1

    There is a special plugin component-directory-webpack-plugin , configured as follows:

    Installation:

    npm i component-directory-webpack-plugin -S

    Setup:

     // webpack.config.js var ComponentDirectoryPlugin = require('component-directory-webpack-plugin'); module.exports = { resolve: { plugins: [new ComponentDirectoryPlugin()] extensions: ['', '.js', '.jsx'] } };