diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index e60835cee0..2d3b668bbf 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -17,6 +17,7 @@ // Kyle Uehlein // Grgur Grisogono // Rubens Pinheiro Gonçalves Cavalcante +// Anders Kaseorg // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -153,7 +154,7 @@ declare namespace webpack { /** When used in tandem with output.library and output.libraryTarget, this option allows users to insert comments within the export wrapper. */ auxiliaryComment?: string | AuxiliaryCommentObject; /** The filename of the entry chunk as relative path inside the output.path directory. */ - filename?: string; + filename?: string | ((chunkData: ChunkData) => string); /** The filename of non-entry chunks as relative path inside the output.path directory. */ chunkFilename?: string; /** Number of milliseconds before chunk request expires, defaults to 120,000. */ @@ -234,6 +235,10 @@ declare namespace webpack { type AuxiliaryCommentObject = { [P in LibraryTarget]: string }; + interface ChunkData { + chunk: compilation.Chunk; + } + interface Module { /** A array of applied pre loaders. */ preLoaders?: RuleSetRule[]; diff --git a/types/webpack/webpack-tests.ts b/types/webpack/webpack-tests.ts index 1194961622..1ad0885224 100644 --- a/types/webpack/webpack-tests.ts +++ b/types/webpack/webpack-tests.ts @@ -989,3 +989,12 @@ webpack.Template.renderChunkModules( [], 'a', ); + +// https://webpack.js.org/configuration/output/#outputfilename +configuration = { + output: { + filename: chunkData => { + return chunkData.chunk.name === 'main' ? '[name].js' : '[name]/[name].js'; + }, + }, +};