From 5015d80ab505d59941a5dbd9dd45829b159ac1b2 Mon Sep 17 00:00:00 2001 From: Michael Strobel Date: Sat, 10 Jun 2017 09:05:34 +0800 Subject: [PATCH 1/2] [webpack] Add types for CommonsChunkPlugin.Options --- types/webpack/index.d.ts | 54 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index 9e5d106b80..1793eeef4f 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -907,7 +907,59 @@ declare namespace webpack { } class CommonsChunkPlugin extends Plugin { - constructor(options?: any); + constructor(options?: CommonsChunkPlugin.Options); + } + + namespace CommonsChunkPlugin { + type MinChunksFn = (module: any, count: number) => boolean; + + interface Options { + /** + * The chunk name of the commons chunk. An existing chunk can be selected by passing a name of an existing chunk. + * If an array of strings is passed this is equal to invoking the plugin multiple times for each chunk name. + * If omitted and `options.async` or `options.children` is set all chunks are used, + * otherwise `options.filename` is used as chunk name. + */ + name?: string; + names?: string[]; + + /** + * The filename template for the commons chunk. Can contain the same placeholders as `output.filename`. + * If omitted the original filename is not modified (usually `output.filename` or `output.chunkFilename`). + */ + filename?: string; + + /** + * The minimum number of chunks which need to contain a module before it's moved into the commons chunk. + * The number must be greater than or equal 2 and lower than or equal to the number of chunks. + * Passing `Infinity` just creates the commons chunk, but moves no modules into it. + * By providing a `function` you can add custom logic. (Defaults to the number of chunks) + */ + minChunks?: number | MinChunksFn; + + /** + * Select the source chunks by chunk names. The chunk must be a child of the commons chunk. + * If omitted all entry chunks are selected. + */ + chunks?: string[]; + + /** + * If `true` all children of the commons chunk are selected + */ + children?: boolean; + + /** + * If `true` a new async commons chunk is created as child of `options.name` and sibling of `options.chunks`. + * It is loaded in parallel with `options.chunks`. It is possible to change the name of the output file + * by providing the desired string instead of `true`. + */ + async?: boolean | string; + + /** + * Minimum size of all common module before a commons chunk is created. + */ + minSize?: number; + } } /** @deprecated */ From 8b6097d1ddf500ee2f69173cded1b13919c5e7f2 Mon Sep 17 00:00:00 2001 From: Michael Strobel Date: Sat, 10 Jun 2017 09:27:15 +0800 Subject: [PATCH 2/2] Fix whitespace linting error --- types/webpack/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index 1793eeef4f..8d4c7282ca 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -922,7 +922,7 @@ declare namespace webpack { */ name?: string; names?: string[]; - + /** * The filename template for the commons chunk. Can contain the same placeholders as `output.filename`. * If omitted the original filename is not modified (usually `output.filename` or `output.chunkFilename`).