@cocasts/webpack-assets-retry-plugin
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

@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

Readme

Keywords

Package Sidebar

Install

npm i @cocasts/webpack-assets-retry-plugin

Weekly Downloads

2

Version

0.1.2

License

MIT

Unpacked Size

9.36 kB

Total Files

6

Last publish

Collaborators

  • hikii