Open mooyoul opened 7 years ago
I think that's a valid ask. You're proposing using a similar API to how html-webpack-plugin tackles this I assume? :)
Yeah that's correct. I just want to include/exclude some named chunks on preload-webpack-plugin like html-webpack-plugin :)
FYI, previously i was used below snippet (quick & dirty solution) for implementing preload chunks with filtering on my html-webpack-plugin html template file:
<%
Object.keys(webpack.assetsByChunkName)
.filter((k) => k && k.indexOf('CHUNK_NAME_TO_BE_IGNORED') === -1)
.reduce((collection, k) => collection.concat(webpack.assetsByChunkName[k]), [])
.filter((filename) => filename && filename.slice(-3) === '.js')
.forEach((filename) => {
%>
<link rel="preload" href="<%= webpackConfig.output.publicPath %><%= filename %>" as="script">
<% }); %>
The best way would be to use the chunks from htmlPluginData
which gives you the setting for each generated page as you can use multiple html-webpack-plugin instances https://github.com/GoogleChrome/preload-webpack-plugin/blob/7760ef791605c05cd306c0f63ce9b6d6318a2c7c/index.js#L36
This option would be very useful! I wanted to exclude sourcemap's chunks but it seems not possible at the moment...
This would be useful for avoiding sourcemaps - maybe you could pass in a blacklist of regexes/globs to match against? It could be populated with ['*.map']
for a start to stop the plugin including sourcemaps.
@addyosmani I'm happy to attempt a PR if you're happy with that approach, or to talk through it.
This would be useful for avoiding sourcemaps - maybe you could pass in a blacklist of regexes/globs to match against? It could be populated with ['*.map'] for a start to stop the plugin including sourcemaps.
This is useful. We don't want to preload sourcemap.
I opened a PR with the blacklist feature: https://github.com/GoogleChrome/preload-webpack-plugin/pull/16
If anyone needs it for now you can always depend on my version of this repo.
It would be nice if preload-webpack-plugin supports filtering chunks (only include some chunks/exclude some chunks.) like html-webpack-plugin's one.
It will be useful on some use-cases.