text: 
  const glob = require('glob');
  const path = require('path');
  const { CleanWebpackPlugin } = require('clean-webpack-plugin');
  const HtmlWebpackPlugin = require('html-webpack-plugin');
  const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  const autoprefixer = require('autoprefixer');
  
  const projectRoot = process.cwd();
  
  const setMPA = () => {
    const entry = {};
    const htmlWebpackPlugins = [];
  
    const entryFiles = glob.sync(path.join(projectRoot, './src/*/index.js'));
  
    Object.keys(entryFiles).forEach((index) => {
      const entryFile = entryFiles[index];
  
      const match = entryFile.match(/src\/(.*)\/index\.js/);
      const pageName = match && match[1];
  
      entry[pageName] = entryFile;
      htmlWebpackPlugins.push(
        new HtmlWebpackPlugin({
          template: path.join(projectRoot, `src/${pageName}/index.html`),
          filename: `${pageName}.html`,
          chunks: ['commons', 'vendors', pageName],
          inject: true, // 生成的 js css 会自动的注入到这个 html 中
          minify: {
            html5: true,
            collapseWhitespace: true,
            preserveLineBreaks: false,
            minifyCss: true,
            minifyJS: true,
            removeComments: false,
          },
        }),
      );
    });
  
    return {
      entry,
      htmlWebpackPlugins,
    };
  };
  
  const { entry, htmlWebpackPlugins } = setMPA();
  
  module.exports = {
    entry,
    module: {
      rules: [
        {
          test: /.js$/,
          use: [
            'babel-loader',
          ],
        },
        {
          test: /.css$/,
          use: [
            MiniCssExtractPlugin.loader,
            'css-loader',
          ],
        },
        {
          test: /.less$/,
          use: [
            MiniCssExtractPlugin.loader,
            'css-loader',
            {
              loader: 'postcss-loader',
              options: {
                plugins: () => [
                  autoprefixer({
                    overrideBrowserslist: [
                      'last 2 version',
                      '>1%',
                      'ios 7',
                    ],
                  }),
                ],
              },
            },
            {
              loader: 'px2rem-loader',
              options: {
                remUnit: 75,
                remPrecision: 8,
              },
            },
            'less-loader',
          ],
        },
        {
          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 MiniCssExtractPlugin({
        filename: '[name]_[contenthash:8].css',
      }),
      new CleanWebpackPlugin(),
      new FriendlyErrorsWebpackPlugin(), // 更为友好的构建错误输入提示
      function errorPlugin() {
        // this.plugin('done', (stats) => { // webpack3 写法
        this.hooks.done.tap('done', (stats) => { // webpack4 写法
          // webpack4 中可用 echo $? 查看构建结果状态
          // 用于在构建完成后主动捕获并处理构建错误
          if (stats.compilation.errors && stats.compilation.errors.length && process.argv.indexOf('--watch') === -1) {
            process.exit(1);
          }
        });
      },
    ].concat(htmlWebpackPlugins),
    stats: 'errors-only',
  };
  