A webpack plugin to retry load assets based on https://github.com/Nikaple/assets-retry.
$ npm install @cocasts/webpack-assets-retry-plugin
// webpack.config.js
const { AssetsRetryPlugin } = require('@cocasts/webpack-assets-retry-plugin');
plugins: [
new AssetsRetryPlugin({
// domain list, only resources in the domain list will be retried.
domain: ['localhost:3000/', 'localhost:3000/fallback/'],
// maximum retry count for each asset, default is 3
maxRetryCount: 3,
// onRetry hook is how you can customize retry logic with, default is x => x
onRetry: function(currentUrl, originalUrl, statistics) {
return currentUrl
},
// for a given resource (except background-images in css),
// either onSuccess or onFail will be eventually called to
// indicate whether the resource has been successfully loaded
onSuccess: function(currentUrl) {
console.log(currentUrl, assetsRetryStatistics[currentUrl])
},
onFail: function(currentUrl) {
console.log(currentUrl, assetsRetryStatistics[currentUrl])
}
}),
];
- webpack >= 5.0.0
- html-webpack-plugin >=4.0.0
- Reference: Nikaple/assets-retry
MIT