diff --git a/webpack/index.d.ts b/webpack/index.d.ts index 18ab5274ba..0eb787a9b0 100644 --- a/webpack/index.d.ts +++ b/webpack/index.d.ts @@ -783,10 +783,28 @@ declare namespace webpack { namespace optimize { class AggressiveMergingPlugin extends Plugin { - constructor(options?: { - minSize?: number; - maxSize?: number; - }); + constructor(options?: AggressiveMergingPlugin.Options); + } + + namespace AggressiveMergingPlugin { + interface Options { + /** + * When options.moveToParents is set, moving to an entry chunk is more expensive. + * Defaults to 10, which means moving to an entry chunk is ten times more expensive than moving to a + * normal chunk. + */ + entryChunkMultiplicator?: number; + /** + * A factor which defines the minimum required size reduction for chunk merging. + * Defaults to 1.5 which means that the total size needs to be reduced by 50% for chunk merging. + */ + minSizeReduce?: number; + /** + * When set, modules that are not in both merged chunks are moved to all parents of the chunk. + * Defaults to false. + */ + moveToParents?: boolean; + } } class CommonsChunkPlugin extends Plugin { diff --git a/webpack/webpack-tests.ts b/webpack/webpack-tests.ts index 8ab05c1de4..483e175f38 100644 --- a/webpack/webpack-tests.ts +++ b/webpack/webpack-tests.ts @@ -1,6 +1,33 @@ - import * as webpack from 'webpack'; +const { + optimize, +} = webpack; + +let plugins: webpack.Plugin[]; + +/** + * Plugins + */ + +/** + * optimize + */ + +const { + AggressiveMergingPlugin, +} = optimize; + +plugins = [ + new AggressiveMergingPlugin(), + new AggressiveMergingPlugin({}), + new AggressiveMergingPlugin({ + entryChunkMultiplicator: 10, + minSizeReduce: 1.5, + moveToParents: false, + }), +]; + let configuration: webpack.Configuration; let rule: webpack.Rule; let plugin: webpack.Plugin; @@ -236,7 +263,6 @@ declare const context: any; declare const request: any; declare const types: any; declare const banner: any; -const plugins: webpack.Plugin[] = []; plugin = new webpack.NormalModuleReplacementPlugin(resourceRegExp, newResource); plugin = new webpack.ContextReplacementPlugin( @@ -334,7 +360,6 @@ plugin = new CommonsChunkPlugin({ // minChunks: 3, // (3 children must share the module before it's separated) }); -plugin = new webpack.optimize.AggressiveMergingPlugin(options); plugin = new webpack.DefinePlugin(definitions); plugin = new webpack.DefinePlugin({ "VERSION": JSON.stringify("5fa3b9"),