You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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'`:
135
+
You can also configure the plugin to preload all chunks (vendor, async, normal chunks) using `include: 'allChunks'`, or only preload initial chunks with `include: 'initial'`:
It is very common in Webpack to use loaders such as `file-loader` to generate assets for specific
165
+
types, such as fonts or images. If you wish to preload these files as well, you can use `include`
166
+
with value `allAssets`:
167
+
168
+
```js
169
+
plugins: [
170
+
newHtmlWebpackPlugin(),
171
+
newPreloadWebpackPlugin({
172
+
rel:'preload',
173
+
include:'allAssets',
174
+
})
175
+
]
176
+
```
177
+
178
+
One thing worth noticing: `file-loader` provides an option to specify `publicPath` just for assets.
179
+
However, that information seems to be lost when this plugin is doing its job. Thus, this plugin
180
+
will use `publicPath` defined in `output` config. It could be an issue, if `publicPath` in `file-loader`
181
+
and `publicPath` in `webpack` config have different values.
182
+
183
+
Usually you don't want to preload all of them but only keep the necessary resources, you can use
184
+
`fileBlacklist` or `fileWhitelist` shown below to filter.
185
+
164
186
Filtering chunks
165
187
---------------------
166
188
@@ -180,9 +202,31 @@ new PreloadWebpackPlugin({
180
202
})
181
203
```
182
204
183
-
## Filtering Html
205
+
If you use `include="allAssets"`, you might find excluding all unnecessary files one by one a
206
+
bit annoying. In this case, you can use `fileWhitelist` to only include the files you want:
207
+
208
+
```js
209
+
newPreloadWebpackPlugin({
210
+
fileWhitelist: [/\.files/,/\.to/,/\.include/],
211
+
})
212
+
```
213
+
214
+
notice that if `fileWhitelist` is not provided, it will not filter any file out.
215
+
216
+
Also, you could use `fileWhitelist` and `fileBlacklist` together:
217
+
218
+
```js
219
+
newPreloadWebpackPlugin({
220
+
fileWhitelist: [/\.files/,/\.to/,/\.include/],
221
+
fileBlacklist: [/\.files/,/\.to/,/\.exclude/],
222
+
})
223
+
```
224
+
225
+
In example above, only files with name matches `/\.include/` will be included.
184
226
185
-
In some case, you may don't want to preload resource on some file. But using `fileBlacklist` is werid, because you may want to inlcude this chunk on another file. So you can use `excludeHtmlNames` to tell preload plugin to ignore this file.
227
+
## Filtering HTML
228
+
229
+
In some case, you may don't want to preload resource on some file. But using `fileBlacklist` is weird, because you may want to inlcude this chunk on another file. So you can use `excludeHtmlNames` to tell preload plugin to ignore this file.
186
230
187
231
If you have multiple html like index.html and example.html, you can exclude index.html like this.
0 commit comments