ac984560dbbbff534bb8093aeeddebeec6399300075eb68b8d0723f89e30a49ae7368506c8968dcb6e2b774b140889a3013dd53e78e0a572dccc2682b28500 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. import { Tapable } from 'tapable';
  2. import * as webpack from 'webpack';
  3. import * as https from 'https';
  4. export = Config;
  5. declare namespace __Config {
  6. class Chained<Parent> {
  7. end(): Parent;
  8. }
  9. class TypedChainedMap<Parent, Value> extends Chained<Parent> {
  10. clear(): this;
  11. delete(key: string): this;
  12. has(key: string): boolean;
  13. get(key: string): Value;
  14. getOrCompute(key: string, compute: () => Value): Value;
  15. set(key: string, value: Value): this;
  16. merge(obj: { [key: string]: Value }): this;
  17. entries(): { [key: string]: Value };
  18. values(): Value[];
  19. when(
  20. condition: boolean,
  21. trueBrancher: (obj: this) => void,
  22. falseBrancher?: (obj: this) => void,
  23. ): this;
  24. }
  25. class ChainedMap<Parent> extends TypedChainedMap<Parent, any> {}
  26. class TypedChainedSet<Parent, Value> extends Chained<Parent> {
  27. add(value: Value): this;
  28. prepend(value: Value): this;
  29. clear(): this;
  30. delete(key: string): this;
  31. has(key: string): boolean;
  32. merge(arr: Value[]): this;
  33. values(): Value[];
  34. when(
  35. condition: boolean,
  36. trueBrancher: (obj: this) => void,
  37. falseBrancher?: (obj: this) => void,
  38. ): this;
  39. }
  40. class ChainedSet<Parent> extends TypedChainedSet<Parent, any> {}
  41. }
  42. declare class Config extends __Config.ChainedMap<void> {
  43. devServer: Config.DevServer;
  44. entryPoints: Config.TypedChainedMap<Config, Config.EntryPoint>;
  45. module: Config.Module;
  46. node: Config.ChainedMap<this>;
  47. output: Config.Output;
  48. optimization: Config.Optimization;
  49. performance: Config.Performance;
  50. plugins: Config.Plugins<this, webpack.Plugin>;
  51. resolve: Config.Resolve;
  52. resolveLoader: Config.ResolveLoader;
  53. amd(value: { [moduleName: string]: boolean }): this;
  54. bail(value: boolean): this;
  55. cache(value: boolean | any): this;
  56. devtool(value: Config.DevTool): this;
  57. context(value: string): this;
  58. externals(value: webpack.ExternalsElement | webpack.ExternalsElement[]): this;
  59. loader(value: any): this;
  60. name(value: string): this;
  61. mode(value: 'none' | 'development' | 'production'): this;
  62. parallelism(value: number): this;
  63. profile(value: boolean): this;
  64. recordsPath(value: string): this;
  65. recordsInputPath(value: string): this;
  66. recordsOutputPath(value: string): this;
  67. stats(value: webpack.Options.Stats): this;
  68. target(value: string): this;
  69. watch(value: boolean): this;
  70. watchOptions(value: webpack.Options.WatchOptions): this;
  71. entry(name: string): Config.EntryPoint;
  72. plugin(name: string): Config.Plugin<this, webpack.Plugin>;
  73. toConfig(): webpack.Configuration;
  74. }
  75. declare namespace Config {
  76. class Chained<Parent> extends __Config.Chained<Parent> {}
  77. class TypedChainedMap<Parent, Value> extends __Config.TypedChainedMap<
  78. Parent,
  79. Value
  80. > {}
  81. class ChainedMap<Parent> extends __Config.TypedChainedMap<Parent, any> {}
  82. class TypedChainedSet<Parent, Value> extends __Config.TypedChainedSet<
  83. Parent,
  84. Value
  85. > {}
  86. class ChainedSet<Parent> extends __Config.TypedChainedSet<Parent, any> {}
  87. class Plugins<
  88. Parent,
  89. PluginType extends Tapable.Plugin = webpack.Plugin
  90. > extends TypedChainedMap<Parent, Plugin<Parent, PluginType>> {}
  91. class Plugin<Parent, PluginType extends Tapable.Plugin = webpack.Plugin>
  92. extends ChainedMap<Parent>
  93. implements Orderable {
  94. init<P extends PluginType | PluginClass<PluginType>>(
  95. value: (
  96. plugin: P,
  97. args: P extends PluginClass ? ConstructorParameters<P> : any[],
  98. ) => PluginType,
  99. ): this;
  100. use<P extends string | PluginType | PluginClass<PluginType>>(
  101. plugin: P,
  102. args?: P extends PluginClass ? ConstructorParameters<P> : any[],
  103. ): this;
  104. tap<P extends PluginClass<PluginType>>(
  105. f: (args: ConstructorParameters<P>) => ConstructorParameters<P>,
  106. ): this;
  107. // Orderable
  108. before(name: string): this;
  109. after(name: string): this;
  110. }
  111. class Module extends ChainedMap<Config> {
  112. rules: TypedChainedMap<this, Rule>;
  113. rule(name: string): Rule;
  114. noParse(
  115. noParse: RegExp | RegExp[] | ((contentPath: string) => boolean),
  116. ): this;
  117. strictExportPresence(value: boolean): this;
  118. }
  119. class Output extends ChainedMap<Config> {
  120. auxiliaryComment(value: string | { [comment: string]: string }): this;
  121. chunkFilename(value: string): this;
  122. chunkLoadTimeout(value: number): this;
  123. crossOriginLoading(value: boolean | string): this;
  124. filename(value: string): this;
  125. library(value: string): this;
  126. libraryExport(value: string | string[]): this;
  127. libraryTarget(value: string): this;
  128. devtoolFallbackModuleFilenameTemplate(value: any): this;
  129. devtoolLineToLine(value: any): this;
  130. devtoolModuleFilenameTemplate(value: any): this;
  131. devtoolNamespace(value: string): this;
  132. globalObject(value: string): this;
  133. hashFunction(value: string): this;
  134. hashDigest(value: string): this;
  135. hashDigestLength(value: number): this;
  136. hashSalt(value: any): this;
  137. hotUpdateChunkFilename(value: string): this;
  138. hotUpdateFunction(value: any): this;
  139. hotUpdateMainFilename(value: string): this;
  140. jsonpFunction(value: string): this;
  141. path(value: string): this;
  142. pathinfo(value: boolean): this;
  143. publicPath(value: string): this;
  144. sourceMapFilename(value: string): this;
  145. sourcePrefix(value: string): this;
  146. strictModuleExceptionHandling(value: boolean): this;
  147. umdNamedDefine(value: boolean): this;
  148. futureEmitAssets(value: boolean): this;
  149. }
  150. class DevServer extends ChainedMap<Config> {
  151. allowedHosts: TypedChainedSet<this, string>;
  152. after(
  153. value: (app: any, server: any, compiler: webpack.Compiler) => void,
  154. ): this;
  155. before(
  156. value: (app: any, server: any, compiler: webpack.Compiler) => void,
  157. ): this;
  158. bonjour(value: boolean): this;
  159. clientLogLevel(value: 'none' | 'error' | 'warning' | 'info'): this;
  160. color(value: boolean): this;
  161. compress(value: boolean): this;
  162. contentBase(value: boolean | string | string[]): this;
  163. disableHostCheck(value: boolean): this;
  164. filename(value: string): this;
  165. headers(value: { [header: string]: string }): this;
  166. historyApiFallback(value: boolean | any): this;
  167. host(value: string): this;
  168. hot(value: boolean): this;
  169. hotOnly(value: boolean): this;
  170. http2(value: boolean): this;
  171. https(value: boolean | https.ServerOptions): this;
  172. index(value: string): this;
  173. info(value: boolean): this;
  174. inline(value: boolean): this;
  175. lazy(value: boolean): this;
  176. mimeTypes(value: Object): this;
  177. noInfo(value: boolean): this;
  178. open(value: boolean): this;
  179. openPage(value: string | string[]): this;
  180. overlay(value: boolean | { warnings?: boolean; errors?: boolean }): this;
  181. pfx(value: string): this;
  182. pfxPassphrase(value: string): this;
  183. port(value: number): this;
  184. progress(value: boolean): this;
  185. proxy(value: any): this;
  186. public(value: string): this;
  187. publicPath(publicPath: string): this;
  188. quiet(value: boolean): this;
  189. setup(value: (expressApp: any) => void): this;
  190. socket(value: string): this;
  191. sockHost(value: string): this;
  192. sockPath(value: string): this;
  193. sockPort(value: number): this;
  194. staticOptions(value: any): this;
  195. stats(value: webpack.Options.Stats): this;
  196. stdin(value: boolean): this;
  197. useLocalIp(value: boolean): this;
  198. watchContentBase(value: boolean): this;
  199. watchOptions(value: any): this;
  200. writeToDisk(value: boolean): this;
  201. }
  202. class Performance extends ChainedMap<Config> {
  203. hints(value: boolean | 'error' | 'warning'): this;
  204. maxEntrypointSize(value: number): this;
  205. maxAssetSize(value: number): this;
  206. assetFilter(value: (assetFilename: string) => boolean): this;
  207. }
  208. class EntryPoint extends TypedChainedSet<Config, string> {}
  209. class Resolve<T = Config> extends ChainedMap<T> {
  210. alias: TypedChainedMap<this, string>;
  211. aliasFields: TypedChainedSet<this, string>;
  212. descriptionFiles: TypedChainedSet<this, string>;
  213. extensions: TypedChainedSet<this, string>;
  214. mainFields: TypedChainedSet<this, string>;
  215. mainFiles: TypedChainedSet<this, string>;
  216. modules: TypedChainedSet<this, string>;
  217. plugins: TypedChainedMap<this, Plugin<this, webpack.ResolvePlugin>>;
  218. enforceExtension(value: boolean): this;
  219. enforceModuleExtension(value: boolean): this;
  220. unsafeCache(value: boolean | RegExp | RegExp[]): this;
  221. symlinks(value: boolean): this;
  222. cachePredicate(
  223. value: (data: { path: string; request: string }) => boolean,
  224. ): this;
  225. cacheWithContext(value: boolean): this;
  226. plugin(name: string): Plugin<this, webpack.ResolvePlugin>;
  227. }
  228. class ResolveLoader extends Resolve {
  229. moduleExtensions: ChainedSet<this>;
  230. packageMains: ChainedSet<this>;
  231. }
  232. class Rule<T = Module> extends ChainedMap<T> implements Orderable {
  233. rules: TypedChainedMap<this, Rule<Rule>>;
  234. oneOfs: TypedChainedMap<this, Rule<Rule>>;
  235. uses: TypedChainedMap<this, Use>;
  236. include: TypedChainedSet<this, webpack.Condition>;
  237. exclude: TypedChainedSet<this, webpack.Condition>;
  238. resolve: Resolve<Rule<T>>;
  239. parser(value: { [optName: string]: any }): this;
  240. test(value: webpack.Condition | webpack.Condition[]): this;
  241. type(
  242. value:
  243. | 'javascript/auto'
  244. | 'javascript/dynamic'
  245. | 'javascript/esm'
  246. | 'json'
  247. | 'webassembly/experimental',
  248. ): this;
  249. enforce(value: 'pre' | 'post'): this;
  250. use(name: string): Use<this>;
  251. rule(name: string): Rule<Rule>;
  252. oneOf(name: string): Rule<Rule>;
  253. pre(): this;
  254. post(): this;
  255. before(name: string): this;
  256. after(name: string): this;
  257. resourceQuery(value: webpack.Condition | webpack.Condition[]): this;
  258. }
  259. class Optimization extends ChainedMap<Config> {
  260. concatenateModules(value: boolean): this;
  261. flagIncludedChunks(value: boolean): this;
  262. mergeDuplicateChunks(value: boolean): this;
  263. minimize(value: boolean): this;
  264. minimizer(name: string): Config.Plugin<this, webpack.Plugin>;
  265. namedChunks(value: boolean): this;
  266. namedModules(value: boolean): this;
  267. nodeEnv(value: boolean | string): this;
  268. noEmitOnErrors(value: boolean): this;
  269. occurrenceOrder(value: boolean): this;
  270. portableRecords(value: boolean): this;
  271. providedExports(value: boolean): this;
  272. removeAvailableModules(value: boolean): this;
  273. removeEmptyChunks(value: boolean): this;
  274. runtimeChunk(value: boolean | 'single' | 'multiple' | RuntimeChunk): this;
  275. sideEffects(value: boolean): this;
  276. splitChunks(value: SplitChunksOptions): this;
  277. usedExports(value: boolean): this;
  278. }
  279. interface RuntimeChunk {
  280. name: string | RuntimeChunkFunction;
  281. }
  282. type RuntimeChunkFunction = (entryPoint: EntryPoint) => string;
  283. interface SplitChunksOptions {
  284. [name: string]: any;
  285. }
  286. interface LoaderOptions {
  287. [name: string]: any;
  288. }
  289. class Use<Parent = Rule> extends ChainedMap<Parent> implements Orderable {
  290. loader(value: string): this;
  291. options(value: LoaderOptions): this;
  292. tap(f: (options: LoaderOptions) => LoaderOptions): this;
  293. // Orderable
  294. before(name: string): this;
  295. after(name: string): this;
  296. }
  297. type DevTool =
  298. | 'eval'
  299. | 'inline-source-map'
  300. | 'cheap-eval-source-map'
  301. | 'cheap-source-map'
  302. | 'cheap-module-eval-source-map'
  303. | 'cheap-module-source-map'
  304. | 'eval-source-map'
  305. | 'source-map'
  306. | 'nosources-source-map'
  307. | 'hidden-source-map'
  308. | 'nosources-source-map'
  309. | '@eval'
  310. | '@inline-source-map'
  311. | '@cheap-eval-source-map'
  312. | '@cheap-source-map'
  313. | '@cheap-module-eval-source-map'
  314. | '@cheap-module-source-map'
  315. | '@eval-source-map'
  316. | '@source-map'
  317. | '@nosources-source-map'
  318. | '@hidden-source-map'
  319. | '@nosources-source-map'
  320. | '#eval'
  321. | '#inline-source-map'
  322. | '#cheap-eval-source-map'
  323. | '#cheap-source-map'
  324. | '#cheap-module-eval-source-map'
  325. | '#cheap-module-source-map'
  326. | '#eval-source-map'
  327. | '#source-map'
  328. | '#nosources-source-map'
  329. | '#hidden-source-map'
  330. | '#nosources-source-map'
  331. | '#@eval'
  332. | '#@inline-source-map'
  333. | '#@cheap-eval-source-map'
  334. | '#@cheap-source-map'
  335. | '#@cheap-module-eval-source-map'
  336. | '#@cheap-module-source-map'
  337. | '#@eval-source-map'
  338. | '#@source-map'
  339. | '#@nosources-source-map'
  340. | '#@hidden-source-map'
  341. | '#@nosources-source-map'
  342. | boolean;
  343. interface PluginClass<PluginType extends Tapable.Plugin = webpack.Plugin> {
  344. new (...opts: any[]): PluginType;
  345. }
  346. interface Orderable {
  347. before(name: string): this;
  348. after(name: string): this;
  349. }
  350. }