Merge pull request #25781 from mnquintana/webpack-4-split-chunks-chunks-func

[@types/webpack] Add support for chunks filter function in SplitChunksPlugin
This commit is contained in:
Ron Buckton
2018-05-16 22:42:45 -07:00
committed by GitHub
2 changed files with 24 additions and 3 deletions

View File

@@ -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 <https://github.com/tkqubo>
// Benjamin Lim <https://github.com/bumbleblym>
@@ -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: 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";
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 */

View File

@@ -607,6 +607,27 @@ configuration = {
},
};
configuration = {
mode: "production",
optimization: {
splitChunks: {
cacheGroups: {
common: {
name: 'common',
chunks(chunk: webpack.compilation.Chunk) {
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 {}