text: /**
   * Build config for electron renderer process
   */
  
  import path from 'path';
  import webpack from 'webpack';
  import HtmlWebpackPlugin from 'html-webpack-plugin';
  import MiniCssExtractPlugin from 'mini-css-extract-plugin';
  import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
  import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
  import { merge } from 'webpack-merge';
  import TerserPlugin from 'terser-webpack-plugin';
  import baseConfig from './webpack.config.base';
  import webpackPaths from './webpack.paths.js';
  import checkNodeEnv from '../scripts/check-node-env';
  import deleteSourceMaps from '../scripts/delete-source-maps';
  
  checkNodeEnv('production');
  deleteSourceMaps();
  
  const devtoolsConfig =
    process.env.DEBUG_PROD === 'true'
      ? {
          devtool: 'source-map',
        }
      : {};
  
  export default merge(baseConfig, {
    ...devtoolsConfig,
  
    mode: 'production',
  
    target: ['web', 'electron-renderer'],
  
    entry: [
      'core-js',
      'regenerator-runtime/runtime',
      path.join(webpackPaths.srcRendererPath, 'index.tsx'),
    ],
  
    output: {
      path: webpackPaths.distRendererPath,
      publicPath: './',
      filename: 'renderer.js',
      library: {
        type: 'umd',
      },
    },
  
    module: {
      rules: [
        {
          // CSS/SCSS
          test: /\.s?css$/,
          use: [
            {
              loader: MiniCssExtractPlugin.loader,
              options: {
                // `./dist` can't be inerhited for publicPath for styles. Otherwise generated paths will be ./dist/dist
                publicPath: './',
              },
            },
            'css-loader',
            'sass-loader',
            'less-loader',
          ],
        },
        // WOFF Font
        {
          test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
          use: {
            loader: 'url-loader',
            options: {
              limit: 10000,
              mimetype: 'application/font-woff',
            },
          },
        },
        // WOFF2 Font
        {
          test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
          use: {
            loader: 'url-loader',
            options: {
              limit: 10000,
              mimetype: 'application/font-woff',
            },
          },
        },
        // OTF Font
        {
          test: /\.otf(\?v=\d+\.\d+\.\d+)?$/,
          use: {
            loader: 'url-loader',
            options: {
              limit: 10000,
              mimetype: 'font/otf',
            },
          },
        },
        // TTF Font
        {
          test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
          use: {
            loader: 'url-loader',
            options: {
              limit: 10000,
              mimetype: 'application/octet-stream',
            },
          },
        },
        // EOT Font
        {
          test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
          use: 'file-loader',
        },
        // SVG Font
        {
          test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
          use: {
            loader: 'url-loader',
            options: {
              limit: 10000,
              mimetype: 'image/svg+xml',
            },
          },
        },
        // Common Image Formats
        {
          test: /\.(?:ico|gif|png|jpg|jpeg|webp)$/,
          use: 'url-loader',
        },
      ],
    },
  
    optimization: {
      minimize: true,
      minimizer: [
        new TerserPlugin({
          parallel: true,
        }),
        new CssMinimizerPlugin(),
      ],
    },
  
    plugins: [
      /**
       * Create global constants which can be configured at compile time.
       *
       * Useful for allowing different behaviour between development builds and
       * release builds
       *
       * NODE_ENV should be production so that modules do not perform certain
       * development checks
       */
      new webpack.EnvironmentPlugin({
        NODE_ENV: 'production',
        DEBUG_PROD: false,
      }),
  
      new MiniCssExtractPlugin({
        filename: 'style.css',
      }),
  
      new BundleAnalyzerPlugin({
        analyzerMode:
          process.env.OPEN_ANALYZER === 'true' ? 'server' : 'disabled',
        openAnalyzer: process.env.OPEN_ANALYZER === 'true',
      }),
  
      new HtmlWebpackPlugin({
        filename: 'index.html',
        template: path.join(webpackPaths.srcRendererPath, 'index.ejs'),
        minify: {
          collapseWhitespace: true,
          removeAttributeQuotes: true,
          removeComments: true,
        },
        isBrowser: false,
        isDevelopment: process.env.NODE_ENV !== 'production',
      }),
    ],
  });
  