Webpack配置解析文件夹中的索引

时间:2018-04-26 07:22:39

标签: javascript reactjs webpack sass

我有一个项目,我使用webpack,反应,sass。我的项目结构和webpack.config如下。在项目中我需要导入写@import 'styles/BigComp/index.sass'import BigComp from './components/BigComp/Index.jsx',但我想省略“索引”,以某种方式设置webpack配置,它可以弄清楚,如果在文件夹中有文件index.sassIndex.jsx,然后webpack需要导入它。总之,我想写import BigComp from './components/BigComp'来导入./components/BigComp/Index.jsx并写@import 'styles/BigComp'来导入styles/BigComp/index.sass。我希望,我能说清楚。

// 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 },
};

0 个答案:

没有答案