UNPKG

1.23 kBJavaScriptView Raw
1// @ts-check
2/** @typedef {import("webpack/lib/Compilation.js")} WebpackCompilation */
3'use strict';
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 */
9module.exports = {};
10
11/**
12 * Performs identity mapping (no-sort).
13 * @param {Array} chunks the chunks to sort
14 * @return {Array} The sorted chunks
15 */
16module.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 */
25module.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 */
40module.exports.auto = module.exports.none;