<commit_before>const webpack = require("webpack");
const OfflinePlugin = require("offline-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require("path");
const CompressionPlugin = require("compression-webpack-plugin");

function match(x, map) {
  return map[x]();
}

module.exports = (env, argv) => {
  const enableBff = Boolean(env && env["enable-bff"]);

  if (!enableBff && argv.mode === "production") {
    throw new Error("bff must be enabled for production builds.");
  }

  return {
    entry: {
      main: ["./src/main.tsx", "./src/global.scss"],
    },
    output: {
      filename: "[name].[chunkhash].immutable.js",
      path: __dirname + "/dist",
      publicPath: "/",
    },
    resolve: {
      extensions: [".ts", ".tsx", ".js"],
      alias: {
        style: path.resolve(__dirname, "src/style"),
      },
    },
    plugins: [
      new webpack.DefinePlugin({
        __BUILD_DATE__: JSON.stringify(Date.now()),
        __MODE__: JSON.stringify(argv.mode),
        __ENABLE_BFF__: JSON.stringify(enableBff),
        ...(!enableBff
          ? { __ENV__: `env.loadEnv${JSON.stringify(process.env)}` }
          : {}),
      }),
      new OfflinePlugin({
        caches: {
          main: [":rest:"],
        },
        ServiceWorker: {
          output: "sw.js",
          publicPath: "/sw.js",
          cacheName: "anontown",
          minify: true,
        },
      }),
      new HtmlWebpackPlugin({
        inject: false,
        template: "index.ejs",
        filename: enableBff ? ".index.ejs" : "index.html",
        templateParameters: enableBff
          ? {
              enableBff: true,
            }
          : {
              enableBff: false,
            },
      }),
      new CopyWebpackPlugin([
        {
          from: "public",
          to: "",
        },
        {
          from: path.join(
            path.dirname(require.resolve("@anontown/client-icon/package.json")),
            "dist",
          ),
          to: "",
        },
      ]),
      new CleanWebpackPlugin({ cleanStaleWebpackAssets: false }),
      ...match(argv.mode, {
        production: () => [
          new CompressionPlugin({ minRatio: Number.MAX_SAFE_INTEGER }),
        ],
        development: () => [],
      }),
    ],
    module: {
      rules: [
        {
          test: /\.(graphql|gql)$/,
          exclude: /node_modules/,
          loader: "graphql-tag/loader",
        },
        {
          test: /\.tsx?$/,
          loader: "ts-loader",
        },
        {
          test: /\.html?$/,
          loader: "html-loader",
        },
        {
          test: /\.s?css$/,
          use: [
            {
              loader: "style-loader",
            },
            {
              loader: "css-loader?modules",
            },
            {
              loader: "sass-loader",
            },
          ],
        },
      ],
    },
    devtool: match(argv.mode, {
      production: () => false,
      development: () => "source-map",
    }),
    optimization: {
      splitChunks: {
        name: "vendor",
        chunks: "initial",
      },
    },
    devServer: !enableBff
      ? {
          contentBase: path.join(__dirname, "public"),
          port: 3000,
        }
      : undefined,
  };
};
<commit_msg>webpackの設定ミス修正<commit_after>const webpack = require("webpack");
const OfflinePlugin = require("offline-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require("path");
const CompressionPlugin = require("compression-webpack-plugin");

function match(x, map) {
  return map[x]();
}

module.exports = (env, argv) => {
  const enableBff = Boolean(env && env["enable-bff"]);

  if (!enableBff && argv.mode === "production") {
    throw new Error("bff must be enabled for production builds.");
  }

  return {
    entry: {
      main: ["./src/main.tsx", "./src/global.scss"],
    },
    output: {
      filename: "[name].[chunkhash].immutable.js",
      path: __dirname + "/dist",
      publicPath: "/",
    },
    resolve: {
      extensions: [".ts", ".tsx", ".js"],
      alias: {
        style: path.resolve(__dirname, "src/style"),
      },
    },
    plugins: [
      new webpack.DefinePlugin({
        __BUILD_DATE__: JSON.stringify(Date.now()),
        __MODE__: JSON.stringify(argv.mode),
        __ENABLE_BFF__: JSON.stringify(enableBff),
        ...(!enableBff
          ? { __ENV__: `env.loadEnv(${JSON.stringify(process.env)})` }
          : {}),
      }),
      new OfflinePlugin({
        caches: {
          main: [":rest:"],
        },
        ServiceWorker: {
          output: "sw.js",
          publicPath: "/sw.js",
          cacheName: "anontown",
          minify: true,
        },
      }),
      new HtmlWebpackPlugin({
        inject: false,
        template: "index.ejs",
        filename: enableBff ? ".index.ejs" : "index.html",
        templateParameters: enableBff
          ? {
              enableBff: true,
            }
          : {
              enableBff: false,
            },
      }),
      new CopyWebpackPlugin([
        {
          from: "public",
          to: "",
        },
        {
          from: path.join(
            path.dirname(require.resolve("@anontown/client-icon/package.json")),
            "dist",
          ),
          to: "",
        },
      ]),
      new CleanWebpackPlugin({ cleanStaleWebpackAssets: false }),
      ...match(argv.mode, {
        production: () => [
          new CompressionPlugin({ minRatio: Number.MAX_SAFE_INTEGER }),
        ],
        development: () => [],
      }),
    ],
    module: {
      rules: [
        {
          test: /\.(graphql|gql)$/,
          exclude: /node_modules/,
          loader: "graphql-tag/loader",
        },
        {
          test: /\.tsx?$/,
          loader: "ts-loader",
        },
        {
          test: /\.html?$/,
          loader: "html-loader",
        },
        {
          test: /\.s?css$/,
          use: [
            {
              loader: "style-loader",
            },
            {
              loader: "css-loader?modules",
            },
            {
              loader: "sass-loader",
            },
          ],
        },
      ],
    },
    devtool: match(argv.mode, {
      production: () => false,
      development: () => "source-map",
    }),
    optimization: {
      splitChunks: {
        name: "vendor",
        chunks: "initial",
      },
    },
    devServer: !enableBff
      ? {
          contentBase: path.join(__dirname, "public"),
          port: 3000,
        }
      : undefined,
  };
};

{'fraction_non_alphanumeric': 0.16364974245768948, 'fraction_numerical': 0.001177336276674025, 'mean_word_length': 1.5830482706195363, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '5265898', 'n_tokens_mistral': 2050, 'n_tokens_neox': 2034, 'n_words': 350}