@rsbuild/plugin-assets-retry 1.0.1-beta.4 → 1.0.1-beta.5

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/dist/index.cjs CHANGED
@@ -34,143 +34,6 @@ var __publicField = (obj, key, value) => {
34
34
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
35
35
  return value;
36
36
  };
37
- var __accessCheck = (obj, member, msg) => {
38
- if (!member.has(obj))
39
- throw TypeError("Cannot " + msg);
40
- };
41
- var __privateGet = (obj, member, getter) => {
42
- __accessCheck(obj, member, "read from private field");
43
- return getter ? getter.call(obj) : member.get(obj);
44
- };
45
- var __privateAdd = (obj, member, value) => {
46
- if (member.has(obj))
47
- throw TypeError("Cannot add the same private member more than once");
48
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
49
- };
50
- var __privateSet = (obj, member, value, setter) => {
51
- __accessCheck(obj, member, "write to private field");
52
- setter ? setter.call(obj, value) : member.set(obj, value);
53
- return value;
54
- };
55
-
56
- // src/AssetsRetryPlugin.ts
57
- var AssetsRetryPlugin_exports = {};
58
- __export(AssetsRetryPlugin_exports, {
59
- AssetsRetryPlugin: () => AssetsRetryPlugin
60
- });
61
- var import_node_fs, import_node_path, import_core, _retryOptions, AssetsRetryPlugin;
62
- var init_AssetsRetryPlugin = __esm({
63
- "src/AssetsRetryPlugin.ts"() {
64
- "use strict";
65
- import_node_fs = __toESM(require("fs"));
66
- import_node_path = __toESM(require("path"));
67
- import_core = require("@rsbuild/core");
68
- AssetsRetryPlugin = class {
69
- constructor(options) {
70
- __publicField(this, "name");
71
- __publicField(this, "distDir");
72
- __publicField(this, "inlineScript");
73
- __publicField(this, "minify");
74
- __publicField(this, "HtmlPlugin");
75
- __publicField(this, "scriptPath");
76
- __privateAdd(this, _retryOptions, void 0);
77
- const {
78
- distDir,
79
- HtmlPlugin,
80
- inlineScript = true,
81
- minify,
82
- ...retryOptions
83
- } = options;
84
- this.name = "AssetsRetryPlugin";
85
- __privateSet(this, _retryOptions, retryOptions);
86
- this.distDir = distDir;
87
- this.HtmlPlugin = HtmlPlugin;
88
- this.inlineScript = inlineScript;
89
- this.scriptPath = "";
90
- this.minify = minify;
91
- }
92
- async getRetryCode() {
93
- const { default: serialize2 } = await import("serialize-javascript");
94
- const filename = "initialChunkRetry";
95
- const runtimeFilePath = import_node_path.default.join(
96
- __dirname,
97
- "runtime",
98
- this.minify ? `${filename}.min.js` : `${filename}.js`
99
- );
100
- const runtimeCode = await import_node_fs.default.promises.readFile(runtimeFilePath, "utf-8");
101
- return `(function(){${runtimeCode};init(${serialize2(
102
- __privateGet(this, _retryOptions)
103
- )});})()`;
104
- }
105
- async getScriptPath() {
106
- if (!this.scriptPath) {
107
- this.scriptPath = import_node_path.default.posix.join(
108
- this.distDir,
109
- `assets-retry.${"1.0.1-beta.4"}.js`
110
- );
111
- }
112
- return this.scriptPath;
113
- }
114
- apply(compiler) {
115
- if (!this.inlineScript) {
116
- compiler.hooks.thisCompilation.tap(
117
- this.name,
118
- (compilation) => {
119
- compilation.hooks.processAssets.tapPromise(
120
- {
121
- name: this.name,
122
- stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS
123
- },
124
- async () => {
125
- const scriptPath = await this.getScriptPath();
126
- const code = await this.getRetryCode();
127
- compilation.emitAsset(
128
- scriptPath,
129
- new compiler.webpack.sources.RawSource(code, false)
130
- );
131
- }
132
- );
133
- }
134
- );
135
- }
136
- compiler.hooks.compilation.tap(this.name, (compilation) => {
137
- this.HtmlPlugin.getHooks(compilation).alterAssetTagGroups.tapPromise(
138
- this.name,
139
- async (data) => {
140
- const scriptTag = {
141
- tagName: "script",
142
- attributes: {},
143
- voidTag: false,
144
- meta: {}
145
- };
146
- if (this.inlineScript) {
147
- data.headTags.unshift({
148
- ...scriptTag,
149
- innerHTML: await this.getRetryCode()
150
- });
151
- } else {
152
- const { publicPath } = compilation.outputOptions;
153
- const url = (0, import_core.ensureAssetPrefix)(
154
- await this.getScriptPath(),
155
- publicPath
156
- );
157
- data.headTags.unshift({
158
- ...scriptTag,
159
- attributes: {
160
- ...scriptTag.attributes,
161
- src: url
162
- }
163
- });
164
- }
165
- return data;
166
- }
167
- );
168
- });
169
- }
170
- };
171
- _retryOptions = new WeakMap();
172
- }
173
- });
174
37
 
175
38
  // src/AsyncChunkRetryPlugin.ts
176
39
  var AsyncChunkRetryPlugin_exports = {};
@@ -208,13 +71,13 @@ function pick(obj, keys) {
208
71
  {}
209
72
  );
210
73
  }
211
- var import_node_fs2, import_node_path2, import_core2, import_serialize_javascript, AsyncChunkRetryPlugin;
74
+ var import_node_fs, import_node_path, import_core, import_serialize_javascript, AsyncChunkRetryPlugin;
212
75
  var init_AsyncChunkRetryPlugin = __esm({
213
76
  "src/AsyncChunkRetryPlugin.ts"() {
214
77
  "use strict";
215
- import_node_fs2 = __toESM(require("fs"));
216
- import_node_path2 = __toESM(require("path"));
217
- import_core2 = require("@rsbuild/core");
78
+ import_node_fs = __toESM(require("fs"));
79
+ import_node_path = __toESM(require("path"));
80
+ import_core = require("@rsbuild/core");
218
81
  import_serialize_javascript = __toESM(require("serialize-javascript"));
219
82
  AsyncChunkRetryPlugin = class {
220
83
  constructor(options) {
@@ -233,14 +96,14 @@ var init_AsyncChunkRetryPlugin = __esm({
233
96
  ]);
234
97
  }
235
98
  getRawRuntimeRetryCode() {
236
- const { RuntimeGlobals } = import_core2.rspack;
99
+ const { RuntimeGlobals } = import_core.rspack;
237
100
  const filename = "asyncChunkRetry";
238
- const runtimeFilePath = import_node_path2.default.join(
101
+ const runtimeFilePath = import_node_path.default.join(
239
102
  __dirname,
240
103
  "runtime",
241
104
  this.options.minify ? `${filename}.min.js` : `${filename}.js`
242
105
  );
243
- const rawText = import_node_fs2.default.readFileSync(runtimeFilePath, "utf-8");
106
+ const rawText = import_node_fs.default.readFileSync(runtimeFilePath, "utf-8");
244
107
  return rawText.replaceAll("__RUNTIME_GLOBALS_REQUIRE__", RuntimeGlobals.require).replaceAll(
245
108
  "__RUNTIME_GLOBALS_ENSURE_CHUNK__",
246
109
  RuntimeGlobals.ensureChunk
@@ -284,37 +147,84 @@ __export(src_exports, {
284
147
  pluginAssetsRetry: () => pluginAssetsRetry
285
148
  });
286
149
  module.exports = __toCommonJS(src_exports);
150
+ var import_node_fs2 = __toESM(require("fs"));
151
+ var import_node_path2 = __toESM(require("path"));
152
+ var import_core2 = require("@rsbuild/core");
287
153
  var PLUGIN_ASSETS_RETRY_NAME = "rsbuild:assets-retry";
288
- var pluginAssetsRetry = (options = {}) => ({
154
+ async function getRetryCode(options) {
155
+ const { default: serialize2 } = await import("serialize-javascript");
156
+ const filename = "initialChunkRetry";
157
+ const { minify, inlineScript: _, ...restOptions } = options;
158
+ const runtimeFilePath = import_node_path2.default.join(
159
+ __dirname,
160
+ "runtime",
161
+ minify ? `${filename}.min.js` : `${filename}.js`
162
+ );
163
+ const runtimeCode = await import_node_fs2.default.promises.readFile(runtimeFilePath, "utf-8");
164
+ return `(function(){${runtimeCode};init(${serialize2(restOptions)});})()`;
165
+ }
166
+ var pluginAssetsRetry = (userOptions = {}) => ({
289
167
  name: PLUGIN_ASSETS_RETRY_NAME,
290
168
  setup(api) {
291
- api.modifyBundlerChain(
292
- async (chain, { CHAIN_ID, HtmlPlugin, isProd, environment }) => {
293
- const { config, htmlPaths } = environment;
294
- if (!options || Object.keys(htmlPaths).length === 0) {
295
- return;
296
- }
297
- const { AssetsRetryPlugin: AssetsRetryPlugin2 } = await Promise.resolve().then(() => (init_AssetsRetryPlugin(), AssetsRetryPlugin_exports));
298
- const { AsyncChunkRetryPlugin: AsyncChunkRetryPlugin2 } = await Promise.resolve().then(() => (init_AsyncChunkRetryPlugin(), AsyncChunkRetryPlugin_exports));
299
- const distDir = config.output.distPath.js;
300
- if (options.crossOrigin === void 0) {
301
- options.crossOrigin = config.html.crossorigin;
169
+ const { inlineScript = true } = userOptions;
170
+ const getScriptPath = (environment) => {
171
+ const distDir = environment.config.output.distPath.js;
172
+ return import_node_path2.default.posix.join(distDir, `assets-retry.${"1.0.1-beta.5"}.js`);
173
+ };
174
+ const formatOptions = (config) => {
175
+ const options = { ...userOptions };
176
+ if (options.crossOrigin === void 0) {
177
+ options.crossOrigin = config.html.crossorigin;
178
+ }
179
+ if (options.minify === void 0) {
180
+ const minify = typeof config.output.minify === "boolean" ? config.output.minify : config.output.minify?.js;
181
+ options.minify = minify && process.env.NODE_ENV === "production";
182
+ }
183
+ return options;
184
+ };
185
+ if (inlineScript) {
186
+ api.modifyHTMLTags(async ({ headTags, bodyTags }, { environment }) => {
187
+ const code = await getRetryCode(formatOptions(environment.config));
188
+ headTags.unshift({
189
+ tag: "script",
190
+ attrs: {},
191
+ children: code
192
+ });
193
+ return { headTags, bodyTags };
194
+ });
195
+ } else {
196
+ api.modifyHTMLTags(
197
+ async ({ headTags, bodyTags }, { assetPrefix, environment }) => {
198
+ const scriptPath = getScriptPath(environment);
199
+ const url = (0, import_core2.ensureAssetPrefix)(scriptPath, assetPrefix);
200
+ headTags.unshift({
201
+ tag: "script",
202
+ attrs: {
203
+ src: url
204
+ }
205
+ });
206
+ return { headTags, bodyTags };
302
207
  }
303
- if (options.minify === void 0) {
304
- const minify = typeof config.output.minify === "boolean" ? config.output.minify : config.output.minify?.js;
305
- options.minify = minify && isProd;
208
+ );
209
+ api.processAssets(
210
+ { stage: "additional" },
211
+ async ({ sources, compilation, environment }) => {
212
+ const scriptPath = getScriptPath(environment);
213
+ const code = await getRetryCode(formatOptions(environment.config));
214
+ compilation.emitAsset(scriptPath, new sources.RawSource(code));
306
215
  }
307
- chain.plugin(CHAIN_ID.PLUGIN.ASSETS_RETRY).use(AssetsRetryPlugin2, [
308
- {
309
- ...options,
310
- distDir,
311
- HtmlPlugin
312
- }
313
- ]);
314
- const isRspack = api.context.bundlerType === "rspack";
315
- chain.plugin(CHAIN_ID.PLUGIN.ASYNC_CHUNK_RETRY).use(AsyncChunkRetryPlugin2, [{ ...options, isRspack }]);
216
+ );
217
+ }
218
+ api.modifyBundlerChain(async (chain, { environment }) => {
219
+ const { config, htmlPaths } = environment;
220
+ if (!userOptions || Object.keys(htmlPaths).length === 0) {
221
+ return;
316
222
  }
317
- );
223
+ const { AsyncChunkRetryPlugin: AsyncChunkRetryPlugin2 } = await Promise.resolve().then(() => (init_AsyncChunkRetryPlugin(), AsyncChunkRetryPlugin_exports));
224
+ const options = formatOptions(config);
225
+ const isRspack = api.context.bundlerType === "rspack";
226
+ chain.plugin("async-chunk-retry").use(AsyncChunkRetryPlugin2, [{ ...options, isRspack }]);
227
+ });
318
228
  }
319
229
  });
320
230
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@ import type { RsbuildPlugin } from '@rsbuild/core';
2
2
  import type { PluginAssetsRetryOptions } from './types';
3
3
  export type { PluginAssetsRetryOptions };
4
4
  export declare const PLUGIN_ASSETS_RETRY_NAME = "rsbuild:assets-retry";
5
- export declare const pluginAssetsRetry: (options?: PluginAssetsRetryOptions) => RsbuildPlugin;
5
+ export declare const pluginAssetsRetry: (userOptions?: PluginAssetsRetryOptions) => RsbuildPlugin;
package/dist/index.js CHANGED
@@ -15,24 +15,6 @@ var __publicField = (obj, key, value) => {
15
15
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
16
16
  return value;
17
17
  };
18
- var __accessCheck = (obj, member, msg) => {
19
- if (!member.has(obj))
20
- throw TypeError("Cannot " + msg);
21
- };
22
- var __privateGet = (obj, member, getter) => {
23
- __accessCheck(obj, member, "read from private field");
24
- return getter ? getter.call(obj) : member.get(obj);
25
- };
26
- var __privateAdd = (obj, member, value) => {
27
- if (member.has(obj))
28
- throw TypeError("Cannot add the same private member more than once");
29
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
30
- };
31
- var __privateSet = (obj, member, value, setter) => {
32
- __accessCheck(obj, member, "write to private field");
33
- setter ? setter.call(obj, value) : member.set(obj, value);
34
- return value;
35
- };
36
18
 
37
19
  // ../../node_modules/.pnpm/@modern-js+module-tools@2.56.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
38
20
  import { fileURLToPath } from "url";
@@ -47,135 +29,13 @@ var init_esm = __esm({
47
29
  }
48
30
  });
49
31
 
50
- // src/AssetsRetryPlugin.ts
51
- var AssetsRetryPlugin_exports = {};
52
- __export(AssetsRetryPlugin_exports, {
53
- AssetsRetryPlugin: () => AssetsRetryPlugin
54
- });
55
- import fs from "fs";
56
- import path2 from "path";
57
- import {
58
- ensureAssetPrefix
59
- } from "@rsbuild/core";
60
- var _retryOptions, AssetsRetryPlugin;
61
- var init_AssetsRetryPlugin = __esm({
62
- "src/AssetsRetryPlugin.ts"() {
63
- "use strict";
64
- init_esm();
65
- AssetsRetryPlugin = class {
66
- constructor(options) {
67
- __publicField(this, "name");
68
- __publicField(this, "distDir");
69
- __publicField(this, "inlineScript");
70
- __publicField(this, "minify");
71
- __publicField(this, "HtmlPlugin");
72
- __publicField(this, "scriptPath");
73
- __privateAdd(this, _retryOptions, void 0);
74
- const {
75
- distDir,
76
- HtmlPlugin,
77
- inlineScript = true,
78
- minify,
79
- ...retryOptions
80
- } = options;
81
- this.name = "AssetsRetryPlugin";
82
- __privateSet(this, _retryOptions, retryOptions);
83
- this.distDir = distDir;
84
- this.HtmlPlugin = HtmlPlugin;
85
- this.inlineScript = inlineScript;
86
- this.scriptPath = "";
87
- this.minify = minify;
88
- }
89
- async getRetryCode() {
90
- const { default: serialize2 } = await import("serialize-javascript");
91
- const filename = "initialChunkRetry";
92
- const runtimeFilePath = path2.join(
93
- __dirname,
94
- "runtime",
95
- this.minify ? `${filename}.min.js` : `${filename}.js`
96
- );
97
- const runtimeCode = await fs.promises.readFile(runtimeFilePath, "utf-8");
98
- return `(function(){${runtimeCode};init(${serialize2(
99
- __privateGet(this, _retryOptions)
100
- )});})()`;
101
- }
102
- async getScriptPath() {
103
- if (!this.scriptPath) {
104
- this.scriptPath = path2.posix.join(
105
- this.distDir,
106
- `assets-retry.${"1.0.1-beta.4"}.js`
107
- );
108
- }
109
- return this.scriptPath;
110
- }
111
- apply(compiler) {
112
- if (!this.inlineScript) {
113
- compiler.hooks.thisCompilation.tap(
114
- this.name,
115
- (compilation) => {
116
- compilation.hooks.processAssets.tapPromise(
117
- {
118
- name: this.name,
119
- stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS
120
- },
121
- async () => {
122
- const scriptPath = await this.getScriptPath();
123
- const code = await this.getRetryCode();
124
- compilation.emitAsset(
125
- scriptPath,
126
- new compiler.webpack.sources.RawSource(code, false)
127
- );
128
- }
129
- );
130
- }
131
- );
132
- }
133
- compiler.hooks.compilation.tap(this.name, (compilation) => {
134
- this.HtmlPlugin.getHooks(compilation).alterAssetTagGroups.tapPromise(
135
- this.name,
136
- async (data) => {
137
- const scriptTag = {
138
- tagName: "script",
139
- attributes: {},
140
- voidTag: false,
141
- meta: {}
142
- };
143
- if (this.inlineScript) {
144
- data.headTags.unshift({
145
- ...scriptTag,
146
- innerHTML: await this.getRetryCode()
147
- });
148
- } else {
149
- const { publicPath } = compilation.outputOptions;
150
- const url = ensureAssetPrefix(
151
- await this.getScriptPath(),
152
- publicPath
153
- );
154
- data.headTags.unshift({
155
- ...scriptTag,
156
- attributes: {
157
- ...scriptTag.attributes,
158
- src: url
159
- }
160
- });
161
- }
162
- return data;
163
- }
164
- );
165
- });
166
- }
167
- };
168
- _retryOptions = new WeakMap();
169
- }
170
- });
171
-
172
32
  // src/AsyncChunkRetryPlugin.ts
173
33
  var AsyncChunkRetryPlugin_exports = {};
174
34
  __export(AsyncChunkRetryPlugin_exports, {
175
35
  AsyncChunkRetryPlugin: () => AsyncChunkRetryPlugin
176
36
  });
177
- import fs2 from "fs";
178
- import path3 from "path";
37
+ import fs from "fs";
38
+ import path2 from "path";
179
39
  import { rspack } from "@rsbuild/core";
180
40
  import serialize from "serialize-javascript";
181
41
  function appendWebpackScript(module, appendSource) {
@@ -233,12 +93,12 @@ var init_AsyncChunkRetryPlugin = __esm({
233
93
  getRawRuntimeRetryCode() {
234
94
  const { RuntimeGlobals } = rspack;
235
95
  const filename = "asyncChunkRetry";
236
- const runtimeFilePath = path3.join(
96
+ const runtimeFilePath = path2.join(
237
97
  __dirname,
238
98
  "runtime",
239
99
  this.options.minify ? `${filename}.min.js` : `${filename}.js`
240
100
  );
241
- const rawText = fs2.readFileSync(runtimeFilePath, "utf-8");
101
+ const rawText = fs.readFileSync(runtimeFilePath, "utf-8");
242
102
  return rawText.replaceAll("__RUNTIME_GLOBALS_REQUIRE__", RuntimeGlobals.require).replaceAll(
243
103
  "__RUNTIME_GLOBALS_ENSURE_CHUNK__",
244
104
  RuntimeGlobals.ensureChunk
@@ -277,37 +137,84 @@ var init_AsyncChunkRetryPlugin = __esm({
277
137
 
278
138
  // src/index.ts
279
139
  init_esm();
140
+ import fs2 from "fs";
141
+ import path3 from "path";
142
+ import { ensureAssetPrefix } from "@rsbuild/core";
280
143
  var PLUGIN_ASSETS_RETRY_NAME = "rsbuild:assets-retry";
281
- var pluginAssetsRetry = (options = {}) => ({
144
+ async function getRetryCode(options) {
145
+ const { default: serialize2 } = await import("serialize-javascript");
146
+ const filename = "initialChunkRetry";
147
+ const { minify, inlineScript: _, ...restOptions } = options;
148
+ const runtimeFilePath = path3.join(
149
+ __dirname,
150
+ "runtime",
151
+ minify ? `${filename}.min.js` : `${filename}.js`
152
+ );
153
+ const runtimeCode = await fs2.promises.readFile(runtimeFilePath, "utf-8");
154
+ return `(function(){${runtimeCode};init(${serialize2(restOptions)});})()`;
155
+ }
156
+ var pluginAssetsRetry = (userOptions = {}) => ({
282
157
  name: PLUGIN_ASSETS_RETRY_NAME,
283
158
  setup(api) {
284
- api.modifyBundlerChain(
285
- async (chain, { CHAIN_ID, HtmlPlugin, isProd, environment }) => {
286
- const { config, htmlPaths } = environment;
287
- if (!options || Object.keys(htmlPaths).length === 0) {
288
- return;
289
- }
290
- const { AssetsRetryPlugin: AssetsRetryPlugin2 } = await Promise.resolve().then(() => (init_AssetsRetryPlugin(), AssetsRetryPlugin_exports));
291
- const { AsyncChunkRetryPlugin: AsyncChunkRetryPlugin2 } = await Promise.resolve().then(() => (init_AsyncChunkRetryPlugin(), AsyncChunkRetryPlugin_exports));
292
- const distDir = config.output.distPath.js;
293
- if (options.crossOrigin === void 0) {
294
- options.crossOrigin = config.html.crossorigin;
159
+ const { inlineScript = true } = userOptions;
160
+ const getScriptPath = (environment) => {
161
+ const distDir = environment.config.output.distPath.js;
162
+ return path3.posix.join(distDir, `assets-retry.${"1.0.1-beta.5"}.js`);
163
+ };
164
+ const formatOptions = (config) => {
165
+ const options = { ...userOptions };
166
+ if (options.crossOrigin === void 0) {
167
+ options.crossOrigin = config.html.crossorigin;
168
+ }
169
+ if (options.minify === void 0) {
170
+ const minify = typeof config.output.minify === "boolean" ? config.output.minify : config.output.minify?.js;
171
+ options.minify = minify && process.env.NODE_ENV === "production";
172
+ }
173
+ return options;
174
+ };
175
+ if (inlineScript) {
176
+ api.modifyHTMLTags(async ({ headTags, bodyTags }, { environment }) => {
177
+ const code = await getRetryCode(formatOptions(environment.config));
178
+ headTags.unshift({
179
+ tag: "script",
180
+ attrs: {},
181
+ children: code
182
+ });
183
+ return { headTags, bodyTags };
184
+ });
185
+ } else {
186
+ api.modifyHTMLTags(
187
+ async ({ headTags, bodyTags }, { assetPrefix, environment }) => {
188
+ const scriptPath = getScriptPath(environment);
189
+ const url = ensureAssetPrefix(scriptPath, assetPrefix);
190
+ headTags.unshift({
191
+ tag: "script",
192
+ attrs: {
193
+ src: url
194
+ }
195
+ });
196
+ return { headTags, bodyTags };
295
197
  }
296
- if (options.minify === void 0) {
297
- const minify = typeof config.output.minify === "boolean" ? config.output.minify : config.output.minify?.js;
298
- options.minify = minify && isProd;
198
+ );
199
+ api.processAssets(
200
+ { stage: "additional" },
201
+ async ({ sources, compilation, environment }) => {
202
+ const scriptPath = getScriptPath(environment);
203
+ const code = await getRetryCode(formatOptions(environment.config));
204
+ compilation.emitAsset(scriptPath, new sources.RawSource(code));
299
205
  }
300
- chain.plugin(CHAIN_ID.PLUGIN.ASSETS_RETRY).use(AssetsRetryPlugin2, [
301
- {
302
- ...options,
303
- distDir,
304
- HtmlPlugin
305
- }
306
- ]);
307
- const isRspack = api.context.bundlerType === "rspack";
308
- chain.plugin(CHAIN_ID.PLUGIN.ASYNC_CHUNK_RETRY).use(AsyncChunkRetryPlugin2, [{ ...options, isRspack }]);
206
+ );
207
+ }
208
+ api.modifyBundlerChain(async (chain, { environment }) => {
209
+ const { config, htmlPaths } = environment;
210
+ if (!userOptions || Object.keys(htmlPaths).length === 0) {
211
+ return;
309
212
  }
310
- );
213
+ const { AsyncChunkRetryPlugin: AsyncChunkRetryPlugin2 } = await Promise.resolve().then(() => (init_AsyncChunkRetryPlugin(), AsyncChunkRetryPlugin_exports));
214
+ const options = formatOptions(config);
215
+ const isRspack = api.context.bundlerType === "rspack";
216
+ chain.plugin("async-chunk-retry").use(AsyncChunkRetryPlugin2, [{ ...options, isRspack }]);
217
+ });
311
218
  }
312
219
  });
313
220
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-assets-retry",
3
- "version": "1.0.1-beta.4",
3
+ "version": "1.0.1-beta.5",
4
4
  "description": "Assets retry plugin for Rsbuild",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "repository": {
@@ -32,7 +32,7 @@
32
32
  "@types/serialize-javascript": "^5.0.4",
33
33
  "terser": "5.31.3",
34
34
  "typescript": "^5.5.2",
35
- "@rsbuild/core": "1.0.1-beta.4"
35
+ "@rsbuild/core": "1.0.1-beta.5"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@rsbuild/core": "^1.0.1-beta.0"
@@ -1,18 +0,0 @@
1
- import { type HtmlRspackPlugin, type Rspack } from '@rsbuild/core';
2
- import type { PluginAssetsRetryOptions } from './types';
3
- export declare class AssetsRetryPlugin implements Rspack.RspackPluginInstance {
4
- #private;
5
- readonly name: string;
6
- readonly distDir: string;
7
- readonly inlineScript: boolean;
8
- readonly minify?: boolean;
9
- readonly HtmlPlugin: typeof HtmlRspackPlugin;
10
- scriptPath: string;
11
- constructor(options: PluginAssetsRetryOptions & {
12
- distDir: string;
13
- HtmlPlugin: typeof HtmlRspackPlugin;
14
- });
15
- getRetryCode(): Promise<string>;
16
- getScriptPath(): Promise<string>;
17
- apply(compiler: Rspack.Compiler): void;
18
- }