import HtmlWebpackPlugin = require("html-webpack-plugin"); import type { Object as JsonObject } from "json-typescript"; import type { Configuration } from "webpack"; declare let webpackConfiguration: Required; declare let htmlOptions: Required; declare namespace WebpackConfig { /** An entry point or entry points as defined by webpack. * * @see https://webpack.js.org/concepts/entry-points/ */ type Entry = typeof webpackConfiguration.entry; /** Simplified webpack configuration. */ interface Project { /** The root directory of the project. * * The path will be resolved relative to the directory containing * the file that called `config()` (usually `webpack.config.cjs`). * * @default "." */ readonly rootDir?: string; /** The directory where webpack will write build output. * * The path will be resolved relative to the resolved root directory * (`this.rootDir`). * * @default "dist" */ readonly destDir?: string; /** The title of the project. * * This value is used as the title of the generated index.html file. */ readonly title: string; /** CSS vendor prefix. * * This value is prepended to all CSS class names. This is useful if * there is third-party code on the same page, to help avoid CSS * conflicts. * * Set to the empty string to disable this feature. * * @deprecated Deprecated, use `css: { namespace: "sv" }` instead. * @default "sv" */ readonly vendor?: string; /** The entry point or entry points. * * @see https://webpack.js.org/concepts/entry-points/ */ readonly entry?: Entry; /** A set of static global variables that will be defined for every * module. * * For each key and value, the key specifies the name of the variable * and the value specifies the value. * * @default {} */ readonly define?: JsonObject; /** Configures webpack to generate an index.html file that loads the * entry points. * * To generate an index.html file with the default settings, set this * field to `true`. * * To suppress generation of an index.html file, set this field to * `false`. * * The generate an index.html file with custom settings, set this field * to an object that specifies the desired settings. * * @default true */ readonly html?: { /** Path to a template file used to generate index.html. * * The path will be resolved relative to the resolved root directory * (`this.rootDir`). * * The template file will be interpreted as a * [Lodash template](https://lodash.com/docs/4.17.15#template). * * The path to the template file must not contain an exclamation mark (`!`). * * @see https://github.com/jantimon/html-webpack-plugin#writing-your-own-templates */ readonly template?: typeof htmlOptions.template; /** Additional parameters to pass to the index.html template. */ readonly templateParameters?: typeof htmlOptions.templateParameters; } | boolean; /** Options that control how webpack handles CSS. */ readonly css?: { /** Whether to embed CSS in JavaScript, or load it from the * generated index.html. * * When building in development mode, this option is ignored and * CSS is always embedded in JavaScript. * * @default "load-from-html" */ readonly mode?: "embed-in-js" | "load-from-html"; /** CSS Modules configuration. * * If set to an object, CSS Modules are enabled. In this case CSS * class names are mangled at compile time. This is useful when * composing together components which each have their own CSS, to * prevent name conflicts between unrelated CSS Modules. * * If set to `false`, CSS Modules are disabled, and CSS class names * are not mangled. This is useful when CSS class names must be * maintained as-is at runtime, for example because the class names * are referenced from static HTML. * * By default, CSS modules are enabled. * * @see https://github.com/css-modules/css-modules * * @default { namespace: "sv" } */ readonly modules?: { /** A namespace that is prefixed to all CSS class names, to * further reduce the likelihood of name conflicts. * * Defaults to `"sv"`, for Software Ventures Limited. * * @default "sv" */ readonly namespace?: string; } | false; }; /** Callback that provides an opportunity to customize the webpack * configuration generated by webpack-config. * * webpack-config calls this function after it has generated a * configuration based on the other settings. The function receives * that configuration as an argument. The function may modify the * configuration provided. The function must return a webpack * configuration, which may either be the original configuration * with or without modifications, or a new configuration. * * The actual webpack configuration used will be the configuration * that is returned by this function. */ readonly customize?: (configuration: Configuration) => Configuration; } /** A Simplified webpack configuration, or a function that returns a * simplified webpack configuration. * * @param mode The mode the project is being built in, either * `"development"` or `"production"`. * * @param env The [environment](https://webpack.js.org/guides/environment-variables/) * that was passed to webpack, for example using `--env` command-line options. */ type ProjectSource = Project | ((mode: "production" | "development", env: JsonObject) => Project); } declare function WebpackConfig(projectSource: WebpackConfig.ProjectSource): (env: unknown) => Configuration; export = WebpackConfig;