text: const { CleanWebpackPlugin } = require('clean-webpack-plugin');
  const path = require('path');
  const HtmlWebpackPlugin = require('html-webpack-plugin');
  const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  const glob = require('glob');
  const autoPreFixer = require('autoprefixer');
  
  const projectRoot = process.cwd();
  
  
  const setMPA = () => {
    const entry = {};
    const htmlWebpackPlugins = [];
    const entryFiles = glob.sync(path.join(projectRoot, './src/*/index.js'));// 'C:/programe/example-code/my-project/src/index/index.js'
  
    Object.keys(entryFiles).map((index) => {
      const entryFile = entryFiles[index];
      const match = entryFile.match(/src\/(.*)\/index\.js/);
      // [ 'src/index/index.js',
      // 'index',
      // index: 36,
      // input: 'C:/programe/example-code/my-project/src/index/index.js',
      // groups: undefined ]
      const pageName = match[1];
      entry[pageName] = entryFile;
      return htmlWebpackPlugins.push(
        new HtmlWebpackPlugin({
          template: path.join(projectRoot, `src/${pageName}/index.html`),
          filename: `${pageName}.html`,
          chunks: ['vendors', pageName],
          inject: true,
          minify: {
            html5: true,
            collapseWhitespace: true,
            preserveLineBreaks: false,
            minifyCSS: false,
            minifyJS: true,
            removeComments: false,
          },
        }),
      );
    });
  
    return {
      entry,
      htmlWebpackPlugins,
    };
  };
  const { entry, htmlWebpackPlugins} = setMPA();
  module.exports = {
    entry: entry,
    output: {
      path: path.join(projectRoot, 'dist'),
      filename: '[name]_[chunkhash:8].js'
    },
    module: {
      rules: [
        {
          test: /.js$/,
          use: 'babel-loader',
          // use:['babel-loader', 'eslint-loader']//Error syntax detection
        },
        {
          test: /.css$/,
          use: [
            MiniCssExtractPlugin.loader,
            'css-loader',
          ],
        },
        {
          test: /.less$/,
          use: [
            MiniCssExtractPlugin.loader,
            'css-loader',
            'less-loader',
            {
              loader: 'postcss-loader',
              options: {
                plugins: () => [
                  autoPreFixer({
                    overrideBrowserslist: ['last 2 version', '>1%', 'ios 7'],
                  }),
                ],
              },
            },
            {
              loader: 'px2rem-loader',
              options: {
                remUnit: 25, // 1rem=75px
                remPrecision: 8, // px 转为rem的小数位数
              },
            },
          ],
        },
        {
          test: /.(png|jpg|gif|jpeg)$/,
          use: [
            {
              loader: 'file-loader',
              options: {
                name: '[name]_[hash:8].[ext]',
              },
            },
          ],
        },
        {
          test: /.(woff|woff2|eot|ttf|otf)$/,
          use: [
            {
              loader: 'file-loader',
              options: {
                name: '[name]_[hash:8].[ext]',
              },
            },
          ],
        },
      ],
    },
  
    plugins: [
      new CleanWebpackPlugin(),
      new FriendlyErrorsWebpackPlugin(),
      new MiniCssExtractPlugin({
        filename: '[name]_[contenthash:8].css',
      }),
      function doneErrorPlugin() {
        this.hooks.done.tap('done', (stats) => {
          if (stats.compilation.errors && stats.compilation.errors.length
            && process.argv.indexOf('--watch') === -1) {
            console.log('build error');//eslint-disable-line
            process.exit(1);
          }
        });
      },
    ].concat(htmlWebpackPlugins),
    stats: 'errors-only',
  };
  