From 3bbf7b10dc17530c54fc52d36b3271af651b65da Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 8 Jan 2018 21:51:45 -0500 Subject: [PATCH] support include: 'initial' --- README.md | 5 ++--- index.js | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5fd8c0b..9bb1415 100644 --- a/README.md +++ b/README.md @@ -132,15 +132,14 @@ will be injected into the document ``: ``` -You can also configure the plugin to preload all chunks (vendor, async, normal chunks) using -`include`: +You can also configure the plugin to preload all chunks (vendor, async, normal chunks) using `include: 'all'`, or only preload initial chunks with `include: 'initial'`: ```js plugins: [ new HtmlWebpackPlugin(), new PreloadWebpackPlugin({ rel: 'preload', - include: 'all' + include: 'all' // or 'initial' }) ] ``` diff --git a/index.js b/index.js index a96ea6d..0277c71 100644 --- a/index.js +++ b/index.js @@ -73,6 +73,12 @@ class PreloadPlugin { } catch (e) { extractedChunks = compilation.chunks; } + } else if (options.include === 'initial') { + try { + extractedChunks = compilation.chunks.filter(chunk => chunk.isInitial()); + } catch (e) { + extractedChunks = compilation.chunks; + } } else if (options.include === 'all') { // Async chunks, vendor chunks, normal chunks. extractedChunks = compilation.chunks;