import type { AsyncSeriesWaterfallHook } from 'tapable'; import type { Compiler } from 'webpack'; import { getIdentifier } from '@rushstack/module-minifier'; import { ILocalMinifierOptions } from '@rushstack/module-minifier'; import { IMinifierConnection } from '@rushstack/module-minifier'; import { IModuleMinificationCallback } from '@rushstack/module-minifier'; import { IModuleMinificationErrorResult } from '@rushstack/module-minifier'; import { IModuleMinificationRequest } from '@rushstack/module-minifier'; import { IModuleMinificationResult } from '@rushstack/module-minifier'; import { IModuleMinificationSuccessResult } from '@rushstack/module-minifier'; import { IModuleMinifier } from '@rushstack/module-minifier'; import { IModuleMinifierFunction } from '@rushstack/module-minifier'; import { IWorkerPoolMinifierOptions } from '@rushstack/module-minifier'; import { LocalMinifier } from '@rushstack/module-minifier'; import { MessagePortMinifier } from '@rushstack/module-minifier'; import { NoopMinifier } from '@rushstack/module-minifier'; import type { Plugin } from 'webpack'; import type { ReplaceSource } from 'webpack-sources'; import { Source } from 'webpack-sources'; import type { SyncWaterfallHook } from 'tapable'; import * as webpack from 'webpack'; import { WorkerPoolMinifier } from '@rushstack/module-minifier'; /** * Token to replace the object or array of module definitions so that the minifier can operate on the Webpack runtime or chunk boilerplate in isolation * @public */ export declare const CHUNK_MODULES_TOKEN: '__WEBPACK_CHUNK_MODULES__'; /** * Generates a companion asset containing all extracted comments. If it is non-empty, returns a banner comment directing users to said companion asset. * * @param compilation - The webpack compilation * @param asset - The asset to process * @param minifiedModules - The minified modules to pull comments from * @param assetName - The name of the asset * @public */ export declare function generateLicenseFileForAsset(compilation: webpack.compilation.Compilation, asset: IAssetInfo, minifiedModules: IModuleMap): string; export { getIdentifier } /** * The comment objects from the Acorn parser inside of webpack * @internal */ export declare interface _IAcornComment { type: 'Line' | 'Block'; value: string; start: number; end: number; } /** * Information about a dehydrated webpack ECMAScript asset * @public */ export declare interface IAssetInfo { /** * The (minified) boilerplate code for the asset. Will contain a token to be replaced by the minified modules. */ source: Source; /** * The name of the asset, used to index into compilation.assets */ fileName: string; /** * The ids of the modules that are part of the chunk corresponding to this asset */ modules: (string | number)[]; /** * Information about the offsets and character lengths for each rendered module in the final asset. */ renderInfo: Map; /** * The raw chunk object from Webpack, in case information from it is necessary for reconstruction */ chunk: webpack.compilation.Chunk; /** * The set of external names to postprocess */ externalNames: Map; } /** * A map from file names to dehydrated assets * @public */ export declare type IAssetMap = Map; /** * Rendered positional data * @public */ export declare interface IAssetStats { positionByModuleId: Map; } /** * The set of data remaining to rehydrate in the current compilation * @public */ export declare interface IDehydratedAssets { /** * The set of remaining assets to rehydrate. Each tap may remove some or all assets from this collection */ assets: IAssetMap; /** * The set of modules to use for rehydrating assets. */ modules: IModuleMap; } /** * Extension of the webpack Module typings with members that are used by this Plugin * @public */ export declare interface IExtendedModule extends webpack.compilation.Module { /** * Is this module external? */ external?: boolean; /** * Concatenated modules */ modules?: IExtendedModule[]; /** * Recursively scan the dependencies of a module */ hasDependencies(callback: (dep: webpack.compilation.Dependency) => boolean | void): boolean; /** * Id for the module */ id: string | number | null; /** * Gets a descriptive identifier for the module. */ identifier(): string; /** * Gets a friendly identifier for the module. */ readableIdentifier(requestShortener: unknown): string; /** * Path to the physical file this module represents */ resource?: string; } export { ILocalMinifierOptions } export { IMinifierConnection } /** * Information about a minified module * @public */ export declare interface IModuleInfo { /** * The (minified) code of this module. Will be a function expression. */ source: Source; /** * The raw module object from Webpack, in case information from it is necessary for reconstruction */ module: IExtendedModule; } /** * A map from module ids to minified modules * @public */ export declare type IModuleMap = Map; export { IModuleMinificationCallback } export { IModuleMinificationErrorResult } export { IModuleMinificationRequest } export { IModuleMinificationResult } export { IModuleMinificationSuccessResult } export { IModuleMinifier } export { IModuleMinifierFunction } /** * Hooks provided by the ModuleMinifierPlugin * @public */ export declare interface IModuleMinifierPluginHooks { /** * Hook invoked at the start of optimizeChunkAssets to rehydrate the minified boilerplate and runtime into chunk assets. */ rehydrateAssets: AsyncSeriesWaterfallHook; /** * Hook invoked on a module id to get the final rendered id. */ finalModuleId: SyncWaterfallHook; /** * Hook invoked on code after it has been returned from the minifier. */ postProcessCodeFragment: SyncWaterfallHook; } /** * Options to the ModuleMinifierPlugin constructor * @public */ export declare interface IModuleMinifierPluginOptions { /** * Minifier implementation to use. Required. */ minifier: IModuleMinifier; /** * Whether to enable source map processing. If not provided, will attempt to guess based on `mode` and `devtool` in the webpack config. * Set to `false` for faster builds at the expense of debuggability. */ sourceMap?: boolean; /** * Instructs the plugin to alter the code of modules to maximize portability across compilations. */ usePortableModules?: boolean; /** * Instructs the plugin to alter the code of async import statements to compress better and be portable across compilations. */ compressAsyncImports?: boolean; } /** * Statistics from the plugin. Namely module sizes. * @public */ export declare interface IModuleMinifierPluginStats { metadataByAssetFileName: Map; } /** * This is the second parameter to the NormalModuleFactory `module` hook * @internal */ export declare interface _INormalModuleFactoryModuleData { resourceResolveData?: { /** * Contents of the description file (package.json) for the module */ descriptionFileData?: { /** * The name of the package */ name: string; }; /** * Absolute path of the description file (package.json) for the module */ descriptionFilePath?: string; /** * Absolute path of the directory containing the description file (package.json) for the module */ descriptionFileRoot?: string; /** * Relative path from the description file (package.json) to the module */ relativePath?: string; }; } /** * Argument to the postProcessCodeFragment hook for the current execution context * @public */ export declare interface IPostProcessFragmentContext { /** * The current webpack compilation, for error reporting */ compilation: webpack.compilation.Compilation; /** * A name to use for logging */ loggingName: string; /** * The current module being processed, or `undefined` if not in a module (e.g. the bootstrapper) */ module: webpack.compilation.Module | undefined; } /** * Information about where the module was rendered in the emitted asset. * @public */ export declare interface IRenderedModulePosition { /** * The offset from the start of tha asset to the start of the module, in characters. */ charOffset: number; /** * The length of the rendered module, in characters. */ charLength: number; } /** * This is the second parameter to the thisCompilation and compilation webpack.Compiler hooks. * @internal */ export declare interface _IWebpackCompilationData { normalModuleFactory: webpack.compilation.NormalModuleFactory; } export { IWorkerPoolMinifierOptions } export { LocalMinifier } export { MessagePortMinifier } /** * Prefix to wrap `function (module, __webpack_exports__, __webpack_require__) { ... }` so that the minifier doesn't delete it. * Public because alternate Minifier implementations may wish to know about it. * @public */ export declare const MODULE_WRAPPER_PREFIX: '__MINIFY_MODULE__('; /** * Suffix to wrap `function (module, __webpack_exports__, __webpack_require__) { ... }` so that the minifier doesn't delete it. * Public because alternate Minifier implementations may wish to know about it. * @public */ export declare const MODULE_WRAPPER_SUFFIX: ');'; /** * Webpack plugin that minifies code on a per-module basis rather than per-asset. The actual minification is handled by the input `minifier` object. * @public */ export declare class ModuleMinifierPlugin implements webpack.Plugin { #private; readonly hooks: IModuleMinifierPluginHooks; minifier: IModuleMinifier; constructor(options: IModuleMinifierPluginOptions); static getCompilationStatistics(compilation: webpack.compilation.Compilation): IModuleMinifierPluginStats | undefined; apply(compiler: webpack.Compiler): void; } export { NoopMinifier } /** * Plugin responsible for converting the Webpack module ids (of whatever variety) to stable ids before code is handed to the minifier, then back again. * Uses the node module identity of the target module. Will emit an error if it encounters multiple versions of the same package in the same compilation. * @public */ export declare class PortableMinifierModuleIdsPlugin implements Plugin { #private; constructor(minifierHooks: IModuleMinifierPluginHooks); apply(compiler: Compiler): void; } /** * Rehydrates an asset with minified modules. * @param asset - The asset * @param moduleMap - The minified modules * @param banner - A banner to inject for license information * @param emitRenderInfo - If set, provide information about module offsets * @public */ export declare function rehydrateAsset(asset: IAssetInfo, moduleMap: IModuleMap, banner: string, emitRenderInfo?: boolean): Source; /** * Stage # to use when this should be the last tap in the hook * @public */ export declare const STAGE_AFTER: 100; /** * Stage # to use when this should be the first tap in the hook * @public */ export declare const STAGE_BEFORE: -100; export { WorkerPoolMinifier } export { }