Skip to content

cocasts/webpack-assets-retry-plugin

Repository files navigation

@cocasts/webpack-assets-retry-plugin

A webpack plugin to retry load assets based on https://github.com/Nikaple/assets-retry.

screenshot 2022-06-18 at 00 47 39

Installation

Install with npm

$ npm install @cocasts/webpack-assets-retry-plugin

Usage

// 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])
    }
  }),
];

Requirements

  • webpack >= 5.0.0
  • html-webpack-plugin >=4.0.0

Principle

License

MIT

About

a webpack plugin base on assets-retry

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published