Get Full Access

Bundler config

/**
 * Defines bundler configuration.
 *
 * @param {"production" | "development"} mode - Mode of the bundler.
 * @param {{outDir?: string, minimize?: boolean, target?: string}} [options]
 *   Can be used to override the default configuration. Optional parameter.
 * @returns {{
 *   mode: "production" | "development",
 *   outDir: string,
 *   target: string,
 *   optimization: {minimize: boolean},
 * }} Bundler configuration.
 */
function defineBundlerConfig(mode, options = {}) {
  const isProduction = mode === "production";

  const defaultOutDir = "dist";
  const defaultTarget = "ES6";
  const defaultMinimize = isProduction;

  const outDir = options.outDir || defaultOutDir;
  const target = options.target || defaultTarget;
  const minimize = options.minimize || defaultMinimize;

  return {
    mode,
    outDir,
    target,
    optimization: {
      minimize,
    },
  };
}