@modern-js/main-doc 2.68.18 → 2.68.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -31,7 +31,7 @@ export type AssetsRetryOptions = {
|
|
|
31
31
|
|
|
32
32
|
- **Default:** `undefined`
|
|
33
33
|
|
|
34
|
-
Since
|
|
34
|
+
- Since this feature injects some runtime code into your HTML and [webpack/Rspack Runtime](https://rspack.rs/api/runtime-api/module-variables), it is disabled by default. To enable it, provide an object for the option, for example:
|
|
35
35
|
|
|
36
36
|
```js
|
|
37
37
|
export default {
|
|
@@ -41,7 +41,7 @@ export default {
|
|
|
41
41
|
};
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
When you enable this
|
|
44
|
+
When you enable this feature, the default configuration for `assetsRetry` is:
|
|
45
45
|
|
|
46
46
|
```ts
|
|
47
47
|
export const defaultAssetsRetryOptions: AssetsRetryOptions = {
|
|
@@ -50,6 +50,7 @@ export const defaultAssetsRetryOptions: AssetsRetryOptions = {
|
|
|
50
50
|
max: 3,
|
|
51
51
|
test: '',
|
|
52
52
|
crossOrigin: false,
|
|
53
|
+
inlineScript: false,
|
|
53
54
|
onRetry: () => {},
|
|
54
55
|
onSuccess: () => {},
|
|
55
56
|
onFail: () => {},
|
|
@@ -62,18 +63,19 @@ You can also customize your retry logic using the `assetsRetry` options.
|
|
|
62
63
|
|
|
63
64
|
For example, setting `assetsRetry.domain` to specify the retry domain when assets fail to load.
|
|
64
65
|
|
|
66
|
+
As an example, you can specify a list of fallback domains via `assetsRetry.domain`. The first domain in the list should match the domain used in your [`assetsPrefix`](./asset-prefix.mdx) configuration:
|
|
67
|
+
|
|
65
68
|
```js
|
|
66
69
|
export default {
|
|
67
70
|
output: {
|
|
68
71
|
assetsRetry: {
|
|
69
|
-
domain: ['
|
|
72
|
+
domain: ['cdn1.com', 'cdn2.com', 'cdn3.com'],
|
|
70
73
|
},
|
|
74
|
+
assetsPrefix: 'https://cdn1.com', // or '//cdn1.com'
|
|
71
75
|
},
|
|
72
76
|
};
|
|
73
77
|
```
|
|
74
78
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
If the assets request for `cdn2.com` also fails, the request will fallback to `cdn3.com`.
|
|
79
|
+
With the configuration above, if an asset fails to load from `cdn1.com`, requests will automatically fall back to `cdn2.com`. If `cdn2.com` also fails, the request will continue to `cdn3.com`.
|
|
78
80
|
|
|
79
81
|
`assetsRetry` is implemented based on the Assets Retry plugin of Rsbuild and provides the same configuration options. You can refer to [Rsbuild - Assets Retry Plugin](https://rsbuild.rs/plugins/list/plugin-assets-retry#options) to understand all available configuration options.
|
|
@@ -31,7 +31,7 @@ export type AssetsRetryOptions = {
|
|
|
31
31
|
|
|
32
32
|
- **默认值:** `undefined`
|
|
33
33
|
|
|
34
|
-
由于该能力会往 HTML
|
|
34
|
+
由于该能力会往 HTML 中和 [webpack/Rspack Runtime](https://rspack.rs/api/runtime-api/module-variables) 注入额外的一些运行时代码,因此我们默认关闭了该能力,如果需要开启该能力,你可以添加以下配置:
|
|
35
35
|
|
|
36
36
|
```js
|
|
37
37
|
export default {
|
|
@@ -50,6 +50,7 @@ export const defaultAssetsRetryOptions: AssetsRetryOptions = {
|
|
|
50
50
|
max: 3,
|
|
51
51
|
test: '',
|
|
52
52
|
crossOrigin: false,
|
|
53
|
+
inlineScript: false,
|
|
53
54
|
onRetry: () => {},
|
|
54
55
|
onSuccess: () => {},
|
|
55
56
|
onFail: () => {},
|
|
@@ -60,14 +61,15 @@ export const defaultAssetsRetryOptions: AssetsRetryOptions = {
|
|
|
60
61
|
|
|
61
62
|
你可以通过 `assetsRetry` 配置项,来定制你的重试逻辑。
|
|
62
63
|
|
|
63
|
-
如,通过 `assetsRetry.domain`
|
|
64
|
+
如,通过 `assetsRetry.domain` 指定资源加载失败时的重试域名列表,第一个域名应该与 [`assetsPrefix`](./asset-prefix.mdx) 配置中的域名保持一致:
|
|
64
65
|
|
|
65
66
|
```js
|
|
66
67
|
export default {
|
|
67
68
|
output: {
|
|
68
69
|
assetsRetry: {
|
|
69
|
-
domain: ['
|
|
70
|
+
domain: ['cdn1.com', 'cdn2.com', 'cdn3.com'],
|
|
70
71
|
},
|
|
72
|
+
assetsPrefix: 'https://cdn1.com', // 或 '//cdn1.com'
|
|
71
73
|
},
|
|
72
74
|
};
|
|
73
75
|
```
|
package/package.json
CHANGED
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.68.
|
|
18
|
+
"version": "2.68.19",
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"registry": "https://registry.npmjs.org/",
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"mermaid": "^11.4.1",
|
|
25
|
-
"@modern-js/sandpack-react": "2.68.
|
|
25
|
+
"@modern-js/sandpack-react": "2.68.19"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@rsbuild/plugin-sass": "1.4.0",
|