<commit_before>const webpack = require('webpack');

const path = require('path');
const fs = require('fs');
const { execSync } = require('child_process');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const { InjectManifest } = require('workbox-webpack-plugin');
const WebpackNotifierPlugin = require('webpack-notifier');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const GenerateJsonPlugin = require('generate-json-webpack-plugin');
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const csp = require('./content-security-policy');
const PacktrackerPlugin = require('@packtracker/webpack-plugin');
const browserslist = require('browserslist');
const ForkTsCheckerNotifierWebpackPlugin = require('fork-ts-checker-notifier-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const svgToMiniDataURI = require('mini-svg-data-uri');
const marked = require('marked');
const renderer = new marked.Renderer();
const _ = require('lodash');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');

const NotifyPlugin = require('notify-webpack-plugin');

const ASSET_NAME_PATTERN = 'static/[name]-[contenthash:6].[ext]';

const packageJson = require('../package.json');

const splash = require('../icons/splash.json');

module.exports = (env) => {
  if (env.dev && env.WEBPACK_SERVE && (!fs.existsSync('key.pem') || !fs.existsSync('cert.pem'))) {
    console.log('Generating certificate');
    execSync('mkcert create-ca --validity 825');
    execSync('mkcert create-cert --validity 825 --key key.pem --cert cert.pem');
  }

  env.name = Object.keys(env)[0];
  ['release', 'beta', 'dev'].forEach((e) => {
    // set booleans based on env
    env[e] = Boolean(env[e]);
    if (env[e]) {
      env.name = e;
    }
  });

  let version = packageJson.version.toString();
  // We start the github build number from 1,000,000 so we don't get clashes with travis build numbers.
  const buildNumber = parseInt(process.env.GITHUB_RUN_NUMBER) + 1_000_000;
  if (env.beta && buildNumber) {
    version += `.${buildNumber}`;
  }

  const buildTime = Date.now();

  const config = {
    mode: env.dev ? 'development' : 'production',

    entry: {
      main: './src/Index.tsx',
      browsercheck: './src/browsercheck.js',
      authReturn: './src/authReturn.ts',
    },

    // https://github.com/webpack/webpack-dev-server/issues/2758
    target: env.dev ? 'web' : 'browserslist',

    output: {
      path: path.resolve('./dist'),
      publicPath: '/',
      filename: env.dev ? '[name]-[fullhash].js' : '[name]-[contenthash:6].js',
      chunkFilename: env.dev ? '[name]-[fullhash].js' : '[name]-[contenthash:6].js',
      assetModuleFilename: ASSET_NAME_PATTERN,
      hashFunction: 'xxhash64',
    },

    // Dev server
    devServer: env.dev
      ? {
          host: process.env.DOCKER ? '0.0.0.0' : 'localhost',
          https: {
            key: fs.readFileSync('key.pem'), // Private keys in PEM format.
            cert: fs.readFileSync('cert.pem'), // Cert chains in PEM format.
          },
          devMiddleware: {
            stats: 'errors-only',
          },
          client: {
            overlay: false,
          },
          historyApiFallback: true,
          hot: 'only',
          liveReload: false,
        }
      : undefined,

    // Bail and fail hard on first error
    bail: !env.dev,

    stats: env.dev ? 'minimal' : 'normal',

    devtool: 'source-map',

    performance: {
      // Don't warn about too-large chunks
      hints: false,
    },

    optimization: {<commit_msg>webpack: https is deprecated, use server and options<commit_after>const webpack = require('webpack');

const path = require('path');
const fs = require('fs');
const { execSync } = require('child_process');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const { InjectManifest } = require('workbox-webpack-plugin');
const WebpackNotifierPlugin = require('webpack-notifier');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const GenerateJsonPlugin = require('generate-json-webpack-plugin');
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const csp = require('./content-security-policy');
const PacktrackerPlugin = require('@packtracker/webpack-plugin');
const browserslist = require('browserslist');
const ForkTsCheckerNotifierWebpackPlugin = require('fork-ts-checker-notifier-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const svgToMiniDataURI = require('mini-svg-data-uri');
const marked = require('marked');
const renderer = new marked.Renderer();
const _ = require('lodash');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');

const NotifyPlugin = require('notify-webpack-plugin');

const ASSET_NAME_PATTERN = 'static/[name]-[contenthash:6].[ext]';

const packageJson = require('../package.json');

const splash = require('../icons/splash.json');

module.exports = (env) => {
  if (env.dev && env.WEBPACK_SERVE && (!fs.existsSync('key.pem') || !fs.existsSync('cert.pem'))) {
    console.log('Generating certificate');
    execSync('mkcert create-ca --validity 825');
    execSync('mkcert create-cert --validity 825 --key key.pem --cert cert.pem');
  }

  env.name = Object.keys(env)[0];
  ['release', 'beta', 'dev'].forEach((e) => {
    // set booleans based on env
    env[e] = Boolean(env[e]);
    if (env[e]) {
      env.name = e;
    }
  });

  let version = packageJson.version.toString();
  // We start the github build number from 1,000,000 so we don't get clashes with travis build numbers.
  const buildNumber = parseInt(process.env.GITHUB_RUN_NUMBER) + 1_000_000;
  if (env.beta && buildNumber) {
    version += `.${buildNumber}`;
  }

  const buildTime = Date.now();

  const config = {
    mode: env.dev ? 'development' : 'production',

    entry: {
      main: './src/Index.tsx',
      browsercheck: './src/browsercheck.js',
      authReturn: './src/authReturn.ts',
    },

    // https://github.com/webpack/webpack-dev-server/issues/2758
    target: env.dev ? 'web' : 'browserslist',

    output: {
      path: path.resolve('./dist'),
      publicPath: '/',
      filename: env.dev ? '[name]-[fullhash].js' : '[name]-[contenthash:6].js',
      chunkFilename: env.dev ? '[name]-[fullhash].js' : '[name]-[contenthash:6].js',
      assetModuleFilename: ASSET_NAME_PATTERN,
      hashFunction: 'xxhash64',
    },

    // Dev server
    devServer: env.dev
      ? {
          host: process.env.DOCKER ? '0.0.0.0' : 'localhost',
          server: {
            type: 'https',
            options: {
              key: fs.readFileSync('key.pem'), // Private keys in PEM format.
              cert: fs.readFileSync('cert.pem'), // Cert chains in PEM format.
            },
          },
          devMiddleware: {
            stats: 'errors-only',
          },
          client: {
            overlay: false,
          },
          historyApiFallback: true,
          hot: 'only',
          liveReload: false,
        }
      : undefined,

    // Bail and fail hard on first error
    bail: !env.dev,

    stats: env.dev ? 'minimal' : 'normal',

    devtool: 'source-map',

    performance: {
      // Don't warn about too-large chunks
      hints: false,
    },

    optimization: {
{'fraction_non_alphanumeric': 0.160498636540709, 'fraction_numerical': 0.008830022075055188, 'mean_word_length': 3.257600884466556, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1629855', 'n_tokens_mistral': 2470, 'n_tokens_neox': 2376, 'n_words': 498}