<commit_before>const path = require('path');
const { merge } = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');

const commonConfig = require('./webpack.config.common');
const parts = require('./webpack.parts');

const NUSMODS_ENV = parts.env();

const source = (file) => path.join('entry/export', file);

const timetableOnlyConfig = merge([
  commonConfig,
  {
    // Override common's entry point
    entry: source('main.tsx'),
    // Don't attempt to continue if there are any errors.
    bail: true,
    mode: NUSMODS_ENV === 'development' ? 'development' : 'production',
    // We generate sourcemaps in production. This is slow but gives good results.
    // You can exclude the *.map files from the build during deployment.
    devtool: 'source-map',
    output: {
      publicPath: parts.TIMETABLE_ONLY_PUBLIC_PATH,
      path: parts.PATHS.buildTimetable,
    },
    plugins: [
      new HtmlWebpackPlugin({
        template: path.join(parts.PATHS.src, source('index.html')),
        inject: true,
      }),
      // TODO: Reenable InlineChunkHtmlPlugin in dev once
      // https://github.com/pmmmwh/react-refresh-webpack-plugin/pull/241 is
      // released. Otherwise website crashes on load.
      NUSMODS_ENV !== 'development' &&
        new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/\.(js|css)$/]),
      NUSMODS_ENV === 'development' && new ReactRefreshWebpackPlugin(),
    ].filter(Boolean),
  },
  parts.loadImages({
    include: parts.PATHS.images,
    options: {
      name: 'img/[name].[contenthash].[ext]',
    },
  }),
  parts.productionCSS(),
  parts.devServer(),
]);

module.exports = timetableOnlyConfig;
<commit_msg>Fix HtmlWebpackPlugin timetable-only build JS injection (#3378)<commit_after>const path = require('path');
const { merge } = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');

const commonConfig = require('./webpack.config.common');
const parts = require('./webpack.parts');

const NUSMODS_ENV = parts.env();

const source = (file) => path.join('entry/export', file);

const timetableOnlyConfig = merge([
  commonConfig,
  {
    // Override common's entry point
    entry: source('main.tsx'),
    // Don't attempt to continue if there are any errors.
    bail: true,
    mode: NUSMODS_ENV === 'development' ? 'development' : 'production',
    // We generate sourcemaps in production. This is slow but gives good results.
    // You can exclude the *.map files from the build during deployment.
    devtool: 'source-map',
    output: {
      publicPath: parts.TIMETABLE_ONLY_PUBLIC_PATH,
      path: parts.PATHS.buildTimetable,
    },
    plugins: [
      new HtmlWebpackPlugin({
        scriptLoading: 'blocking',
        template: path.join(parts.PATHS.src, source('index.html')),
        inject: true,
      }),
      // TODO: Reenable InlineChunkHtmlPlugin in dev once
      // https://github.com/pmmmwh/react-refresh-webpack-plugin/pull/241 is
      // released. Otherwise website crashes on load.
      NUSMODS_ENV !== 'development' &&
        new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/\.(js|css)$/]),
      NUSMODS_ENV === 'development' && new ReactRefreshWebpackPlugin(),
    ].filter(Boolean),
  },
  parts.loadImages({
    include: parts.PATHS.images,
    options: {
      name: 'img/[name].[contenthash].[ext]',
    },
  }),
  parts.productionCSS(),
  parts.devServer(),
]);

module.exports = timetableOnlyConfig;

{'fraction_non_alphanumeric': 0.14175736660472524, 'fraction_numerical': 0.002654632333421821, 'mean_word_length': 3.5839416058394162, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '2006042', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1113, 'n_words': 262}