From f41adcaafa9310354b1031ccd6e772e055e946c7 Mon Sep 17 00:00:00 2001 From: 2heal1 Date: Thu, 16 Sep 2021 20:35:17 +0800 Subject: [PATCH] fix: judge include type --- src/index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 4706359..fb43dcf 100644 --- a/src/index.js +++ b/src/index.js @@ -26,6 +26,20 @@ class PreloadPlugin { this.webpackMajorVersion = 4 } + isAllAssets(include) { + const includeType = typeof include; + if (includeType === 'string') { + return include === 'allAssets' + } else if (includeType === 'object') { + if (!Array.isArray(include)) { + return include.type === 'allAssets' + } + return false; + } else { + return false + } + } + generateLinks (compilation, htmlPluginData) { const options = this.options const extractedChunks = extractChunks({ @@ -33,7 +47,7 @@ class PreloadPlugin { optionsInclude: options.include }) - const htmlChunks = options.include === 'allAssets' + const htmlChunks = isAllAssets(options.include) // Handle all chunks. ? extractedChunks // Only handle chunks imported by this HtmlWebpackPlugin.