@rsbuild/plugin-assets-retry 1.4.3 → 1.5.1
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.
- package/README.md +2 -2
- package/README.zh-CN.md +2 -2
- package/dist/index.cjs +17 -11
- package/dist/index.js +18 -12
- package/dist/runtime/asyncChunkRetry.js +1 -1
- package/package.json +17 -17
package/README.md
CHANGED
|
@@ -410,7 +410,7 @@ pluginAssetsRetry({
|
|
|
410
410
|
|
|
411
411
|
## Notes
|
|
412
412
|
|
|
413
|
-
When you use Assets Retry plugin, the Rsbuild injects some runtime code into the HTML and [Rspack Runtime](https://rspack.
|
|
413
|
+
When you use Assets Retry plugin, the Rsbuild injects some runtime code into the HTML and [Rspack Runtime](https://rspack.rs/misc/glossary#runtime), then serializes the Assets Retry plugin config, inserting it into the runtime code. Therefore, you need to be aware of the following:
|
|
414
414
|
|
|
415
415
|
- Avoid configuring sensitive information in Assets Retry plugin, such as internal tokens.
|
|
416
416
|
- Avoid referencing variables or methods outside of `onRetry`, `onSuccess`, and `onFail`.
|
|
@@ -454,7 +454,7 @@ If you need to retry assets in micro-frontend scenarios, please contact the deve
|
|
|
454
454
|
|
|
455
455
|
Assets Retry plugin listens to the page error event to know whether the current resource fails to load and needs to be retried. Therefore, if the resource in the custom template is executed earlier than Assets Retry plugin, then Assets Retry plugin cannot listen to the event that the resource fails to load, so it will not be retried.
|
|
456
456
|
|
|
457
|
-
If you want Assets Retry plugin to work on resources in custom templates, you can refer to [Custom Insertion Example](https://github.com/
|
|
457
|
+
If you want Assets Retry plugin to work on resources in custom templates, you can refer to [Custom Insertion Example](https://github.com/rstackjs/html-rspack-plugin/tree/main/examples/custom-insertion-position) to modify [html.inject](/config/html/inject) configuration and custom template.
|
|
458
458
|
|
|
459
459
|
```diff
|
|
460
460
|
<!DOCTYPE html>
|
package/README.zh-CN.md
CHANGED
|
@@ -408,7 +408,7 @@ pluginAssetsRetry({
|
|
|
408
408
|
|
|
409
409
|
## 注意事项
|
|
410
410
|
|
|
411
|
-
当你使用 Assets Retry 插件时,Rsbuild 会分别向 HTML 和 [Rspack Runtime](https://rspack.
|
|
411
|
+
当你使用 Assets Retry 插件时,Rsbuild 会分别向 HTML 和 [Rspack Runtime](https://rspack.rs/zh/misc/glossary#runtime) 中注入运行时代码,并将 Assets Retry 插件配置的内容序列化后插入到这些代码中,因此你需要注意:
|
|
412
412
|
|
|
413
413
|
- 避免在 Assets Retry 插件中配置敏感信息,比如内部使用的 token。
|
|
414
414
|
- 避免在 `onRetry`,`onSuccess`,`onFail` 中引用函数外部的变量或方法。
|
|
@@ -452,7 +452,7 @@ pluginAssetsRetry({
|
|
|
452
452
|
|
|
453
453
|
Assets Retry 插件通过监听页面 error 事件来获悉当前资源是否加载失败需要重试。因此,如果自定义模版中的资源执行早于 Assets Retry 插件,那 Assets Retry 插件无法监听到该资源加载失败的事件,retry 无法对其生效。
|
|
454
454
|
|
|
455
|
-
如果想要 Assets Retry 插件对自定义模版中的资源生效,可参考 [自定义插入示例](https://github.com/
|
|
455
|
+
如果想要 Assets Retry 插件对自定义模版中的资源生效,可参考 [自定义插入示例](https://github.com/rstackjs/html-rspack-plugin/tree/main/examples/custom-insertion-position) 来修改 [html.inject](/config/html/inject) 配置和自定义模版。
|
|
456
456
|
|
|
457
457
|
```diff
|
|
458
458
|
<!DOCTYPE html>
|
package/dist/index.cjs
CHANGED
|
@@ -169,9 +169,9 @@ var __webpack_exports__ = {};
|
|
|
169
169
|
"use strict";
|
|
170
170
|
__webpack_require__.r(__webpack_exports__);
|
|
171
171
|
__webpack_require__.d(__webpack_exports__, {
|
|
172
|
-
|
|
172
|
+
PLUGIN_ASSETS_RETRY_NAME: ()=>PLUGIN_ASSETS_RETRY_NAME,
|
|
173
173
|
ASSETS_RETRY_DATA_ATTRIBUTE: ()=>ASSETS_RETRY_DATA_ATTRIBUTE,
|
|
174
|
-
|
|
174
|
+
pluginAssetsRetry: ()=>pluginAssetsRetry
|
|
175
175
|
});
|
|
176
176
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
177
177
|
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
@@ -226,8 +226,7 @@ var __webpack_exports__ = {};
|
|
|
226
226
|
compiler.hooks.thisCompilation.tap(this.name, (compilation)=>{
|
|
227
227
|
const isRspack = this.isRspack;
|
|
228
228
|
compilation.hooks.runtimeModule.tap(this.name, (module)=>{
|
|
229
|
-
|
|
230
|
-
const constructorName = isRspack ? module.constructorName : null == (_module_constructor = module.constructor) ? void 0 : _module_constructor.name;
|
|
229
|
+
const constructorName = isRspack ? module.constructorName : module.constructor?.name;
|
|
231
230
|
const isCssLoadingRuntimeModule = 'CssLoadingRuntimeModule' === constructorName;
|
|
232
231
|
if (isCssLoadingRuntimeModule) return void modifyRuntimeModule(module, (originSource)=>originSource.replace('var fullhref = __webpack_require__.p + href;', 'var fullhref = __webpack_require__.rbLoadStyleSheet ? __webpack_require__.rbLoadStyleSheet(href, chunkId) : (__webpack_require__.p + href);'), isRspack);
|
|
233
232
|
const isPublicPathModule = 'publicPath' === module.name || 'PublicPathRuntimeModule' === constructorName || 'AutoPublicPathRuntimeModule' === constructorName;
|
|
@@ -289,24 +288,28 @@ var __webpack_exports__ = {};
|
|
|
289
288
|
const runtimeCode = await external_node_fs_default().promises.readFile(runtimeFilePath, 'utf-8');
|
|
290
289
|
return runtimeCode.replace('__RETRY_OPTIONS__', serialize_javascript_default()(runtimeOptions));
|
|
291
290
|
}
|
|
291
|
+
function logNoHtmlRegisterWaring() {
|
|
292
|
+
core_namespaceObject.logger.warn(`[${PLUGIN_ASSETS_RETRY_NAME}] no HTML files are generated in the current environment, so the "initialChunkRetry" script will not be injected. Please make sure to manually include the assets-retry script in your HTML files if needed.`);
|
|
293
|
+
}
|
|
292
294
|
const pluginAssetsRetry = (userOptions = {})=>({
|
|
293
295
|
name: PLUGIN_ASSETS_RETRY_NAME,
|
|
294
296
|
setup (api) {
|
|
295
297
|
const { inlineScript = true } = userOptions;
|
|
296
298
|
const getScriptPath = (environment)=>{
|
|
297
299
|
const distDir = environment.config.output.distPath.js;
|
|
298
|
-
return external_node_path_default().posix.join(distDir, "assets-retry.1-
|
|
300
|
+
return external_node_path_default().posix.join(distDir, "assets-retry.1-5-1.js");
|
|
299
301
|
};
|
|
300
302
|
const getDefaultValueFromRsbuildConfig = (config)=>{
|
|
301
|
-
|
|
302
|
-
const minify = 'boolean' == typeof config.output.minify ? config.output.minify : null == (_config_output_minify = config.output.minify) ? void 0 : _config_output_minify.js;
|
|
303
|
+
const minify = 'boolean' == typeof config.output.minify ? config.output.minify : config.output.minify?.js;
|
|
303
304
|
return {
|
|
304
305
|
crossorigin: config.html.crossorigin,
|
|
305
306
|
minify: Boolean(minify) && 'production' === config.mode
|
|
306
307
|
};
|
|
307
308
|
};
|
|
308
309
|
if (inlineScript) api.modifyHTMLTags(async ({ headTags, bodyTags }, { environment })=>{
|
|
309
|
-
const {
|
|
310
|
+
const { htmlPaths, config } = environment;
|
|
311
|
+
if ('web' === config.output.target && 0 === Object.entries(htmlPaths).length) logNoHtmlRegisterWaring();
|
|
312
|
+
const { minify, crossorigin } = getDefaultValueFromRsbuildConfig(config);
|
|
310
313
|
const runtimeOptions = getRuntimeOptions(userOptions, crossorigin);
|
|
311
314
|
const code = await getRetryCode(runtimeOptions, minify);
|
|
312
315
|
headTags.unshift({
|
|
@@ -323,6 +326,7 @@ var __webpack_exports__ = {};
|
|
|
323
326
|
});
|
|
324
327
|
else {
|
|
325
328
|
api.modifyHTMLTags(async ({ headTags, bodyTags }, { assetPrefix, environment })=>{
|
|
329
|
+
if ('web' === environment.config.output.target && 0 === Object.entries(environment.htmlPaths).length) logNoHtmlRegisterWaring();
|
|
326
330
|
const scriptPath = getScriptPath(environment);
|
|
327
331
|
const url = (0, core_namespaceObject.ensureAssetPrefix)(scriptPath, assetPrefix);
|
|
328
332
|
headTags.unshift({
|
|
@@ -340,16 +344,18 @@ var __webpack_exports__ = {};
|
|
|
340
344
|
api.processAssets({
|
|
341
345
|
stage: 'additional'
|
|
342
346
|
}, async ({ sources, compilation, environment })=>{
|
|
347
|
+
const { config } = environment;
|
|
348
|
+
if ('web' !== config.output.target) return;
|
|
343
349
|
const scriptPath = getScriptPath(environment);
|
|
344
|
-
const { crossorigin, minify } = getDefaultValueFromRsbuildConfig(
|
|
350
|
+
const { crossorigin, minify } = getDefaultValueFromRsbuildConfig(config);
|
|
345
351
|
const runtimeOptions = getRuntimeOptions(userOptions, crossorigin);
|
|
346
352
|
const code = await getRetryCode(runtimeOptions, minify);
|
|
347
353
|
compilation.emitAsset(scriptPath, new sources.RawSource(code));
|
|
348
354
|
});
|
|
349
355
|
}
|
|
350
356
|
api.modifyBundlerChain(async (chain, { environment })=>{
|
|
351
|
-
const { config
|
|
352
|
-
if (
|
|
357
|
+
const { config } = environment;
|
|
358
|
+
if ('web' !== config.output.target) return;
|
|
353
359
|
const { crossorigin, minify } = getDefaultValueFromRsbuildConfig(config);
|
|
354
360
|
const runtimeOptions = getRuntimeOptions(userOptions, crossorigin);
|
|
355
361
|
const isRspack = 'rspack' === api.context.bundlerType;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as __rspack_external_crypto from "crypto";
|
|
2
2
|
import node_fs from "node:fs";
|
|
3
3
|
import node_path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { ensureAssetPrefix, rspack } from "@rsbuild/core";
|
|
5
|
+
import { ensureAssetPrefix, logger, rspack } from "@rsbuild/core";
|
|
6
6
|
var __webpack_modules__ = {
|
|
7
7
|
"./node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
8
8
|
module.exports = __webpack_require__("crypto").randomBytes;
|
|
@@ -121,7 +121,7 @@ var __webpack_modules__ = {
|
|
|
121
121
|
};
|
|
122
122
|
},
|
|
123
123
|
crypto: function(module) {
|
|
124
|
-
module.exports =
|
|
124
|
+
module.exports = __rspack_external_crypto;
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
127
|
var __webpack_module_cache__ = {};
|
|
@@ -201,8 +201,7 @@ class AsyncChunkRetryPlugin {
|
|
|
201
201
|
compiler.hooks.thisCompilation.tap(this.name, (compilation)=>{
|
|
202
202
|
const isRspack = this.isRspack;
|
|
203
203
|
compilation.hooks.runtimeModule.tap(this.name, (module)=>{
|
|
204
|
-
|
|
205
|
-
const constructorName = isRspack ? module.constructorName : null == (_module_constructor = module.constructor) ? void 0 : _module_constructor.name;
|
|
204
|
+
const constructorName = isRspack ? module.constructorName : module.constructor?.name;
|
|
206
205
|
const isCssLoadingRuntimeModule = 'CssLoadingRuntimeModule' === constructorName;
|
|
207
206
|
if (isCssLoadingRuntimeModule) return void modifyRuntimeModule(module, (originSource)=>originSource.replace('var fullhref = __webpack_require__.p + href;', 'var fullhref = __webpack_require__.rbLoadStyleSheet ? __webpack_require__.rbLoadStyleSheet(href, chunkId) : (__webpack_require__.p + href);'), isRspack);
|
|
208
207
|
const isPublicPathModule = 'publicPath' === module.name || 'PublicPathRuntimeModule' === constructorName || 'AutoPublicPathRuntimeModule' === constructorName;
|
|
@@ -264,24 +263,28 @@ async function getRetryCode(runtimeOptions, minify) {
|
|
|
264
263
|
const runtimeCode = await node_fs.promises.readFile(runtimeFilePath, 'utf-8');
|
|
265
264
|
return runtimeCode.replace('__RETRY_OPTIONS__', serialize_javascript_default()(runtimeOptions));
|
|
266
265
|
}
|
|
266
|
+
function logNoHtmlRegisterWaring() {
|
|
267
|
+
logger.warn(`[${PLUGIN_ASSETS_RETRY_NAME}] no HTML files are generated in the current environment, so the "initialChunkRetry" script will not be injected. Please make sure to manually include the assets-retry script in your HTML files if needed.`);
|
|
268
|
+
}
|
|
267
269
|
const pluginAssetsRetry = (userOptions = {})=>({
|
|
268
270
|
name: PLUGIN_ASSETS_RETRY_NAME,
|
|
269
271
|
setup (api) {
|
|
270
272
|
const { inlineScript = true } = userOptions;
|
|
271
273
|
const getScriptPath = (environment)=>{
|
|
272
274
|
const distDir = environment.config.output.distPath.js;
|
|
273
|
-
return node_path.posix.join(distDir, "assets-retry.1-
|
|
275
|
+
return node_path.posix.join(distDir, "assets-retry.1-5-1.js");
|
|
274
276
|
};
|
|
275
277
|
const getDefaultValueFromRsbuildConfig = (config)=>{
|
|
276
|
-
|
|
277
|
-
const minify = 'boolean' == typeof config.output.minify ? config.output.minify : null == (_config_output_minify = config.output.minify) ? void 0 : _config_output_minify.js;
|
|
278
|
+
const minify = 'boolean' == typeof config.output.minify ? config.output.minify : config.output.minify?.js;
|
|
278
279
|
return {
|
|
279
280
|
crossorigin: config.html.crossorigin,
|
|
280
281
|
minify: Boolean(minify) && 'production' === config.mode
|
|
281
282
|
};
|
|
282
283
|
};
|
|
283
284
|
if (inlineScript) api.modifyHTMLTags(async ({ headTags, bodyTags }, { environment })=>{
|
|
284
|
-
const {
|
|
285
|
+
const { htmlPaths, config } = environment;
|
|
286
|
+
if ('web' === config.output.target && 0 === Object.entries(htmlPaths).length) logNoHtmlRegisterWaring();
|
|
287
|
+
const { minify, crossorigin } = getDefaultValueFromRsbuildConfig(config);
|
|
285
288
|
const runtimeOptions = getRuntimeOptions(userOptions, crossorigin);
|
|
286
289
|
const code = await getRetryCode(runtimeOptions, minify);
|
|
287
290
|
headTags.unshift({
|
|
@@ -298,6 +301,7 @@ const pluginAssetsRetry = (userOptions = {})=>({
|
|
|
298
301
|
});
|
|
299
302
|
else {
|
|
300
303
|
api.modifyHTMLTags(async ({ headTags, bodyTags }, { assetPrefix, environment })=>{
|
|
304
|
+
if ('web' === environment.config.output.target && 0 === Object.entries(environment.htmlPaths).length) logNoHtmlRegisterWaring();
|
|
301
305
|
const scriptPath = getScriptPath(environment);
|
|
302
306
|
const url = ensureAssetPrefix(scriptPath, assetPrefix);
|
|
303
307
|
headTags.unshift({
|
|
@@ -315,16 +319,18 @@ const pluginAssetsRetry = (userOptions = {})=>({
|
|
|
315
319
|
api.processAssets({
|
|
316
320
|
stage: 'additional'
|
|
317
321
|
}, async ({ sources, compilation, environment })=>{
|
|
322
|
+
const { config } = environment;
|
|
323
|
+
if ('web' !== config.output.target) return;
|
|
318
324
|
const scriptPath = getScriptPath(environment);
|
|
319
|
-
const { crossorigin, minify } = getDefaultValueFromRsbuildConfig(
|
|
325
|
+
const { crossorigin, minify } = getDefaultValueFromRsbuildConfig(config);
|
|
320
326
|
const runtimeOptions = getRuntimeOptions(userOptions, crossorigin);
|
|
321
327
|
const code = await getRetryCode(runtimeOptions, minify);
|
|
322
328
|
compilation.emitAsset(scriptPath, new sources.RawSource(code));
|
|
323
329
|
});
|
|
324
330
|
}
|
|
325
331
|
api.modifyBundlerChain(async (chain, { environment })=>{
|
|
326
|
-
const { config
|
|
327
|
-
if (
|
|
332
|
+
const { config } = environment;
|
|
333
|
+
if ('web' !== config.output.target) return;
|
|
328
334
|
const { crossorigin, minify } = getDefaultValueFromRsbuildConfig(config);
|
|
329
335
|
const runtimeOptions = getRuntimeOptions(userOptions, crossorigin);
|
|
330
336
|
const isRspack = 'rspack' === api.context.bundlerType;
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
}
|
|
145
145
|
if (!callingCounter || 'number' != typeof callingCounter.count || 'number' != typeof callingCounter.cssFailedCount) return result;
|
|
146
146
|
callingCounter.count += 1;
|
|
147
|
-
return result
|
|
147
|
+
return result.catch(function(error) {
|
|
148
148
|
var _error_message;
|
|
149
149
|
var existRetryTimesAll = callingCounter.count - 1;
|
|
150
150
|
var cssExistRetryTimes = callingCounter.cssFailedCount;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-assets-retry",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "An Rsbuild plugin to automatically resend requests when static assets fail to load.",
|
|
5
|
-
"repository": "https://github.com/
|
|
5
|
+
"repository": "https://github.com/rstackjs/rsbuild-plugin-assets-retry",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"exports": {
|
|
@@ -30,32 +30,32 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@biomejs/biome": "^1.9.4",
|
|
33
|
-
"@microsoft/api-extractor": "^7.
|
|
34
|
-
"@playwright/test": "^1.
|
|
35
|
-
"@rsbuild/core": "^1.
|
|
36
|
-
"@rsbuild/plugin-react": "^1.4.
|
|
37
|
-
"@rslib/core": "^0.
|
|
38
|
-
"@swc/core": "^1.
|
|
39
|
-
"@types/node": "^
|
|
40
|
-
"@types/react": "^19.
|
|
41
|
-
"@types/react-dom": "^19.
|
|
33
|
+
"@microsoft/api-extractor": "^7.55.1",
|
|
34
|
+
"@playwright/test": "^1.57.0",
|
|
35
|
+
"@rsbuild/core": "^1.6.10",
|
|
36
|
+
"@rsbuild/plugin-react": "^1.4.2",
|
|
37
|
+
"@rslib/core": "^0.18.2",
|
|
38
|
+
"@swc/core": "^1.15.3",
|
|
39
|
+
"@types/node": "^24.10.1",
|
|
40
|
+
"@types/react": "^19.2.7",
|
|
41
|
+
"@types/react-dom": "^19.2.3",
|
|
42
42
|
"@types/serialize-javascript": "^5.0.4",
|
|
43
|
-
"playwright": "^1.
|
|
44
|
-
"react": "^19.
|
|
45
|
-
"react-dom": "^19.
|
|
43
|
+
"playwright": "^1.57.0",
|
|
44
|
+
"react": "^19.2.0",
|
|
45
|
+
"react-dom": "^19.2.0",
|
|
46
46
|
"serialize-javascript": "^6.0.2",
|
|
47
47
|
"simple-git-hooks": "^2.13.1",
|
|
48
|
-
"typescript": "^5.9.
|
|
48
|
+
"typescript": "^5.9.3"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@rsbuild/core": "1.
|
|
51
|
+
"@rsbuild/core": "^1.0.0 || ^2.0.0-0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependenciesMeta": {
|
|
54
54
|
"@rsbuild/core": {
|
|
55
55
|
"optional": true
|
|
56
56
|
}
|
|
57
57
|
},
|
|
58
|
-
"packageManager": "pnpm@10.
|
|
58
|
+
"packageManager": "pnpm@10.24.0",
|
|
59
59
|
"publishConfig": {
|
|
60
60
|
"access": "public",
|
|
61
61
|
"registry": "https://registry.npmjs.org/"
|