1 | // @ts-check
|
2 | /** @typedef {import("webpack/lib/Compilation.js")} WebpackCompilation */
|
3 | ;
|
4 |
|
5 | /**
|
6 | * @type {{[sortmode: string] : (entryPointNames: Array<string>, compilation, htmlWebpackPluginOptions) => Array<string> }}
|
7 | * This file contains different sort methods for the entry chunks names
|
8 | */
|
9 | module.exports = {};
|
10 |
|
11 | /**
|
12 | * Performs identity mapping (no-sort).
|
13 | * @param {Array} chunks the chunks to sort
|
14 | * @return {Array} The sorted chunks
|
15 | */
|
16 | module.exports.none = chunks => chunks;
|
17 |
|
18 | /**
|
19 | * Sort manually by the chunks
|
20 | * @param {string[]} entryPointNames the chunks to sort
|
21 | * @param {WebpackCompilation} compilation the webpack compilation
|
22 | * @param htmlWebpackPluginOptions the plugin options
|
23 | * @return {string[]} The sorted chunks
|
24 | */
|
25 | module.exports.manual = (entryPointNames, compilation, htmlWebpackPluginOptions) => {
|
26 | const chunks = htmlWebpackPluginOptions.chunks;
|
27 | if (!Array.isArray(chunks)) {
|
28 | return entryPointNames;
|
29 | }
|
30 | // Remove none existing entries from
|
31 | // htmlWebpackPluginOptions.chunks
|
32 | return chunks.filter((entryPointName) => {
|
33 | return compilation.entrypoints.has(entryPointName);
|
34 | });
|
35 | };
|
36 |
|
37 | /**
|
38 | * Defines the default sorter.
|
39 | */
|
40 | module.exports.auto = module.exports.none;
|