UNPKG

@kcws/rspack-config

Version:
79 lines (62 loc) 3.3 kB
import type { Configuration } from '@rspack/core'; import type { RspackPluginFunction } from '@rspack/core'; import type { RspackPluginInstance } from '@rspack/core'; declare type Condition = () => boolean; /** * @beta */ export declare class ConfigBuilder<Transformers extends ConfigTransformers> { private wrapper; private transformers; constructor(config: Configuration, transformers: Transformers); set(config: Configuration): this; add(config: Configuration): this; use<Name extends keyof Transformers>(name: Name, ...params: TransformerParams<Transformers[Name]>): this; build(): Configuration; } /** * @public */ export declare class ConfigService<Transformers extends ConfigTransformers> { static define<Name extends string, Params extends unknown[], Transformer extends ConfigTransformer<Params> = ConfigTransformer<Params>>(name: Name, transformer: Transformer): ConfigService<{ [name in Name]: Transformer; }>; static builder(config?: Configuration): ConfigBuilder<{}>; private readonly transformers; private constructor(); define<Name extends string, Params extends unknown[], Transformer extends ConfigTransformer<Params> = ConfigTransformer<Params>>(name: Name, transformer: Transformer): ConfigService<Merge<Transformers, Name, Transformer>>; builder(config?: Configuration): ConfigBuilder<Transformers>; } /** * @public */ export declare type ConfigTransformer<Params extends unknown[] = unknown[]> = (input: ConfigWrapper, ...params: Params) => ConfigWrapper; /** * @public */ export declare type ConfigTransformers = Record<string, ConfigTransformer>; declare class ConfigWrapper { private base; constructor(base: Configuration); get config(): Configuration; set(config: Configuration): ConfigWrapper; merge(config: Configuration): ConfigWrapper; setEntry(input: Entry, condition?: Condition): ConfigWrapper; addEntry(input: EntryRecord, condition?: Condition): ConfigWrapper; addRelativeEntry(input: EntryStringRecord, condition?: Condition): ConfigWrapper; addEntryByName(name: string, value: EntryRecordValue, condition?: Condition): ConfigWrapper; addRelativeEntryByName(name: string, value: EntryStringRecordValue, condition?: Condition): ConfigWrapper; setPlugins(plugins: Plugins, condition?: Condition): ConfigWrapper; addPlugins(plugin: Plugin, condition?: Condition): ConfigWrapper; private convertEntryRecord; } declare type Entry = Exclude<Configuration["entry"], undefined>; declare type EntryRecord = Extract<Entry, Record<string, unknown> | Function>; declare type EntryRecordValue = Extract<Entry, Record<string, unknown>>[string]; declare type EntryStringRecord = Record<string, EntryStringRecordValue>; declare type EntryStringRecordValue = Extract<EntryRecordValue, string | string[]>; declare type Merge<BaseObject, Key extends string, Value> = BaseObject & { [name in Key]: Value; }; declare type Plugin = RspackPluginInstance | RspackPluginFunction; declare type Plugins = Exclude<Configuration["plugins"], undefined>; declare type TransformerParams<T extends (...args: any) => any> = Parameters<T> extends [unknown, ...infer R] ? R : never; export { }