11import type { CrossOrigin } from '@rsbuild/core' ;
22
3- export type PluginAssetsRetryOptions = {
3+ export type AssetsRetryHookContext = {
4+ url : string ;
5+ times : number ;
6+ domain : string ;
7+ tagName : string ;
8+ isAsyncChunk : boolean ;
9+ } ;
10+
11+ export type RuntimeRetryOptions = {
412 /**
513 * The maximum number of retries for a single asset.
614 * @default 3
@@ -21,7 +29,7 @@ export type PluginAssetsRetryOptions = {
2129 domain ?: string [ ] ;
2230 /**
2331 * Set the `crossorigin` attribute for tags.
24- * @default config .html.crossorigin
32+ * @default rsbuildConfig .html.crossorigin
2533 */
2634 crossOrigin ?: boolean | CrossOrigin ;
2735 /**
@@ -41,11 +49,25 @@ export type PluginAssetsRetryOptions = {
4149 * @param times e.g: 1 -> 2 -> 3
4250 * @param originalQuery initial request url's query e.g: <script src="https://cdn.com/a.js?version=1"></script> -> "?version=1"
4351 * @default false
44- * @description true -> hasQuery(originalQuery) ? `${getQuery(originalQuery)}&retry=${existRetryTimes}` : `?retry=${existRetryTimes}`
52+ * @description
53+ *
54+ * if set to `true`, `?retry=${times}` will be added to the url.
55+ *
56+ * ```ts
57+ * ({ times, originalQuery }) => hasQuery(originalQuery) ? `${getQuery(originalQuery)}&retry=${times}` : `?retry=${times}`
58+ * ```
4559 */
4660 addQuery ?:
4761 | boolean
4862 | ( ( context : { times : number ; originalQuery : string } ) => string ) ;
63+ /**
64+ * The delay time between retries. Unit: ms
65+ * @default 0
66+ */
67+ delay ?: number | ( ( context : AssetsRetryHookContext ) => number ) ;
68+ } ;
69+
70+ export type CompileTimeRetryOptions = {
4971 /**
5072 * Whether to inline the runtime JavaScript code of Assets Retry plugin into the HTML file.
5173 * @default true
@@ -56,22 +78,7 @@ export type PluginAssetsRetryOptions = {
5678 * @default rsbuildConfig.mode === 'production'
5779 */
5880 minify ?: boolean ;
59- /**
60- * The delay time between retries. Unit: ms
61- * @default 0
62- */
63- delay ?: number | ( ( context : AssetsRetryHookContext ) => number ) ;
6481} ;
6582
66- export type RuntimeRetryOptions = Omit <
67- PluginAssetsRetryOptions ,
68- 'inlineScript' | 'minify'
69- > ;
70-
71- export type AssetsRetryHookContext = {
72- url : string ;
73- times : number ;
74- domain : string ;
75- tagName : string ;
76- isAsyncChunk : boolean ;
77- } ;
83+ export type PluginAssetsRetryOptions = RuntimeRetryOptions &
84+ CompileTimeRetryOptions ;
0 commit comments