I have a project, where I use webpack, react, sass. My project structure and webpack.config below. In project I need for purpose to import write @import 'styles/BigComp/index.sass'
or import BigComp from './components/BigComp/Index.jsx'
, but I wanted to omit "index", to set webpack config in a way, that it can figure out, that if in the folder has file index.sass
or Index.jsx
, then webpack need to import it. In conclusion, I want to write import BigComp from './components/BigComp'
to import ./components/BigComp/Index.jsx
and write @import 'styles/BigComp'
to import styles/BigComp/index.sass
. I hope, I make myself clear.
// Do not try to run. It's not a code.
+components
|-+BigComp
|-Index.jsx
|-ElemOfBigComp0.jsx
|-ElemOfBigComp1.jsx
|-ElemOfBigComp2.jsx
+styles
|-+BigComp
|-index.sass
|-elem0.sass
|-elem1.sass
// webpack.config.js
const path = require('path');
const rules = [
{
test: /\.s[ac]ss$/,
use: [
'css-loader',
'sass-loader',
],
},
{
test: /\.jsx?$/,
use: ['babel-loader'],
exclude: ['/node_modules'],
},
];
module.exports = {
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
resolve: {
extensions: ['.js', '.jsx'],
},
module: { rules },
};