text: const webpack = require('webpack');
  const path = require('path');
  const HtmlWebpackPlugin = require('html-webpack-plugin');
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  const TerserJsPlugin = require('terser-webpack-plugin');
  const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
  
  const sourceDirectory = path.resolve(__dirname, './src');
  const targetDirectory = path.resolve(__dirname, './dist');
  
  const isDev = process.env.NODE_ENV !== 'production';
  
  const plugins = [
    new HtmlWebpackPlugin({
      filename: 'index.html',
      inject: true,
      template: path.resolve(__dirname, 'src/index.html'),
      minify: {
        collapseWhitespace: !isDev,
        removeComments: !isDev,
        removeRedundantAttributes: !isDev,
      },
    }),
    new MiniCssExtractPlugin({
      filename: '[name]-[contenthash].css',
      chunkFilename: '[name]-[contenthash].css',
    }),
  ];
  
  if (!isDev) {
    plugins.push(
      new webpack.DefinePlugin({
        'process.env.NODE_ENV': JSON.stringify('production'),
      }),
    );
  }
  
  module.exports = {
    mode: isDev ? 'development' : 'production',
    context: sourceDirectory,
    entry: {
      app: './index.js',
    },
    optimization: {
      minimizer: [
        new TerserJsPlugin({
          parallel: true,
          sourceMap: false,
        }),
        new OptimizeCSSAssetsPlugin({}),
      ],
    },
    output: {
      path: targetDirectory,
      chunkFilename: 'chunk-[chunkhash].js',
      filename: '[name]-[chunkhash].js',
      hashDigestLength: 8,
    },
    devServer: {
      contentBase: sourceDirectory,
      port: 8000,
    },
    node: {
      fs: 'empty',
      module: 'empty',
      net: 'empty',
    },
    module: {
      rules: [
        {
          test: /\.js$/,
          exclude: [/node_modules/],
          use: [
            {
              loader: 'babel-loader',
            },
          ],
        },
        {
          test: /\.(less|css)$/,
          use: [MiniCssExtractPlugin.loader, 'css-loader', 'less-loader'],
          sideEffects: true,
        },
        {
          test: /\.html$/,
          use: [
            {
              loader: 'html-loader',
            },
          ],
        },
      ],
    },
    resolve: {
      alias: {
        'react-docgen': path.resolve(__dirname, '../src/main'),
      },
    },
    plugins,
  };
  