From a351eaac271acd7f4f797d462a4555f4e780c28b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Machist=C3=A9=20Quintana?= Date: Mon, 14 May 2018 17:49:54 -0700 Subject: [PATCH 1/5] Add support for chunks filter function in SplitChunksPlugin --- types/webpack/index.d.ts | 4 ++-- types/webpack/webpack-tests.ts | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index 5be4abdcbd..4dcd7ce89e 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -560,7 +560,7 @@ declare namespace webpack { /** Assign modules to a cache group */ test?: ((...args: any[]) => boolean) | string | RegExp; /** Select chunks for determining cache group content (defaults to \"initial\", \"initial\" and \"all\" requires adding these chunks to the HTML) */ - chunks?: "initial" | "async" | "all"; + chunks?: "initial" | "async" | "all" | ((chunk: any, index?: number, chunks?: any[]) => boolean); /** Ignore minimum size, minimum chunks and maximum requests and always create chunks for this cache group */ enforce?: boolean; /** Priority of this cache group */ @@ -580,7 +580,7 @@ declare namespace webpack { } interface SplitChunksOptions { /** Select chunks for determining shared modules (defaults to \"async\", \"initial\" and \"all\" requires adding these chunks to the HTML) */ - chunks?: "initial" | "async" | "all"; + chunks?: "initial" | "async" | "all" | ((chunk: any, index?: number, chunks?: any[]) => boolean); /** Minimal size for the created chunk */ minSize?: number; /** Minimum number of times a module has to be duplicated until it's considered for splitting */ diff --git a/types/webpack/webpack-tests.ts b/types/webpack/webpack-tests.ts index b42d836c0c..d617c45a17 100644 --- a/types/webpack/webpack-tests.ts +++ b/types/webpack/webpack-tests.ts @@ -607,6 +607,27 @@ configuration = { }, }; +configuration = { + mode: "production", + optimization: { + splitChunks: { + cacheGroups: { + common: { + name: 'common', + chunks(chunk: { name: string }) { + const allowedChunks = [ + 'renderer', + 'component-window', + ]; + return allowedChunks.indexOf(chunk.name) >= 0; + }, + minChunks: 2 + } + } + } + }, +}; + plugin = new webpack.SplitChunksPlugin({ chunks: "async", minChunks: 2 }); class SingleEntryDependency extends webpack.compilation.Dependency {} From 815129e0bb65899edc696a619554700dbbcc990e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Machist=C3=A9=20Quintana?= Date: Mon, 14 May 2018 18:03:37 -0700 Subject: [PATCH 2/5] Use a less strict function type for chunks --- types/webpack/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index 4dcd7ce89e..fb8469dfa5 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -560,7 +560,7 @@ declare namespace webpack { /** Assign modules to a cache group */ test?: ((...args: any[]) => boolean) | string | RegExp; /** Select chunks for determining cache group content (defaults to \"initial\", \"initial\" and \"all\" requires adding these chunks to the HTML) */ - chunks?: "initial" | "async" | "all" | ((chunk: any, index?: number, chunks?: any[]) => boolean); + chunks?: "initial" | "async" | "all" | ((chunk: any) => boolean); /** Ignore minimum size, minimum chunks and maximum requests and always create chunks for this cache group */ enforce?: boolean; /** Priority of this cache group */ @@ -580,7 +580,7 @@ declare namespace webpack { } interface SplitChunksOptions { /** Select chunks for determining shared modules (defaults to \"async\", \"initial\" and \"all\" requires adding these chunks to the HTML) */ - chunks?: "initial" | "async" | "all" | ((chunk: any, index?: number, chunks?: any[]) => boolean); + chunks?: "initial" | "async" | "all" | ((chunk: any) => boolean); /** Minimal size for the created chunk */ minSize?: number; /** Minimum number of times a module has to be duplicated until it's considered for splitting */ From 6744394a0aa73230d72b0f72620e2d11952c14f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Machist=C3=A9=20Quintana?= Date: Tue, 15 May 2018 14:04:28 -0700 Subject: [PATCH 3/5] Bump webpack typings to v4.4.x --- 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 fb8469dfa5..89b12ef1dd 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for webpack 4.1 +// Type definitions for webpack 4.4 // Project: https://github.com/webpack/webpack // Definitions by: Qubo // Benjamin Lim From 3ef1d0d822b95e8eb4ab5be16d8afb62095bdc9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Machist=C3=A9=20Quintana?= Date: Tue, 15 May 2018 14:42:52 -0700 Subject: [PATCH 4/5] Use the actual compilation.Chunk type instead of any --- types/webpack/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index 89b12ef1dd..b49c235d30 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -560,7 +560,7 @@ declare namespace webpack { /** Assign modules to a cache group */ test?: ((...args: any[]) => boolean) | string | RegExp; /** Select chunks for determining cache group content (defaults to \"initial\", \"initial\" and \"all\" requires adding these chunks to the HTML) */ - chunks?: "initial" | "async" | "all" | ((chunk: any) => boolean); + chunks?: "initial" | "async" | "all" | ((chunk: compilation.Chunk) => boolean); /** Ignore minimum size, minimum chunks and maximum requests and always create chunks for this cache group */ enforce?: boolean; /** Priority of this cache group */ @@ -580,7 +580,7 @@ declare namespace webpack { } interface SplitChunksOptions { /** Select chunks for determining shared modules (defaults to \"async\", \"initial\" and \"all\" requires adding these chunks to the HTML) */ - chunks?: "initial" | "async" | "all" | ((chunk: any) => boolean); + chunks?: "initial" | "async" | "all" | ((chunk: compilation.Chunk) => boolean); /** Minimal size for the created chunk */ minSize?: number; /** Minimum number of times a module has to be duplicated until it's considered for splitting */ From c1c69f49136c0b172e85babee8fff3b6a60b58f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Machist=C3=A9=20Quintana?= Date: Tue, 15 May 2018 14:44:42 -0700 Subject: [PATCH 5/5] Update chunks function test to use updated type --- types/webpack/webpack-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/webpack/webpack-tests.ts b/types/webpack/webpack-tests.ts index d617c45a17..3f99d4704f 100644 --- a/types/webpack/webpack-tests.ts +++ b/types/webpack/webpack-tests.ts @@ -614,7 +614,7 @@ configuration = { cacheGroups: { common: { name: 'common', - chunks(chunk: { name: string }) { + chunks(chunk: webpack.compilation.Chunk) { const allowedChunks = [ 'renderer', 'component-window',