@rsbuild/plugin-assets-retry 1.5.1 → 2.0.0
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 +5 -3
- package/README.zh-CN.md +8 -6
- package/dist/index.js +77 -73
- package/dist/runtime/asyncChunkRetry.js +84 -97
- package/dist/runtime/asyncChunkRetry.min.js +1 -1
- package/dist/runtime/initialChunkRetry.js +83 -94
- package/dist/runtime/initialChunkRetry.min.js +1 -1
- package/package.json +29 -29
- package/dist/index.cjs +0 -381
package/dist/index.cjs
DELETED
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
|
|
2
|
-
return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
3
|
-
}();
|
|
4
|
-
var __webpack_modules__ = {
|
|
5
|
-
"./node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
6
|
-
module.exports = __webpack_require__("crypto").randomBytes;
|
|
7
|
-
},
|
|
8
|
-
"./node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
9
|
-
"use strict";
|
|
10
|
-
var randomBytes = __webpack_require__("./node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js");
|
|
11
|
-
var UID_LENGTH = 16;
|
|
12
|
-
var UID = generateUID();
|
|
13
|
-
var PLACE_HOLDER_REGEXP = new RegExp('(\\\\)?"@__(F|R|D|M|S|A|U|I|B|L)-' + UID + '-(\\d+)__@"', 'g');
|
|
14
|
-
var IS_NATIVE_CODE_REGEXP = /\{\s*\[native code\]\s*\}/g;
|
|
15
|
-
var IS_PURE_FUNCTION = /function.*?\(/;
|
|
16
|
-
var IS_ARROW_FUNCTION = /.*?=>.*?/;
|
|
17
|
-
var UNSAFE_CHARS_REGEXP = /[<>\/\u2028\u2029]/g;
|
|
18
|
-
var RESERVED_SYMBOLS = [
|
|
19
|
-
'*',
|
|
20
|
-
'async'
|
|
21
|
-
];
|
|
22
|
-
var ESCAPED_CHARS = {
|
|
23
|
-
'<': '\\u003C',
|
|
24
|
-
'>': '\\u003E',
|
|
25
|
-
'/': '\\u002F',
|
|
26
|
-
'\u2028': '\\u2028',
|
|
27
|
-
'\u2029': '\\u2029'
|
|
28
|
-
};
|
|
29
|
-
function escapeUnsafeChars(unsafeChar) {
|
|
30
|
-
return ESCAPED_CHARS[unsafeChar];
|
|
31
|
-
}
|
|
32
|
-
function generateUID() {
|
|
33
|
-
var bytes = randomBytes(UID_LENGTH);
|
|
34
|
-
var result = '';
|
|
35
|
-
for(var i = 0; i < UID_LENGTH; ++i)result += bytes[i].toString(16);
|
|
36
|
-
return result;
|
|
37
|
-
}
|
|
38
|
-
function deleteFunctions(obj) {
|
|
39
|
-
var functionKeys = [];
|
|
40
|
-
for(var key in obj)if ("function" == typeof obj[key]) functionKeys.push(key);
|
|
41
|
-
for(var i = 0; i < functionKeys.length; i++)delete obj[functionKeys[i]];
|
|
42
|
-
}
|
|
43
|
-
module.exports = function serialize(obj, options) {
|
|
44
|
-
options || (options = {});
|
|
45
|
-
if ('number' == typeof options || 'string' == typeof options) options = {
|
|
46
|
-
space: options
|
|
47
|
-
};
|
|
48
|
-
var functions = [];
|
|
49
|
-
var regexps = [];
|
|
50
|
-
var dates = [];
|
|
51
|
-
var maps = [];
|
|
52
|
-
var sets = [];
|
|
53
|
-
var arrays = [];
|
|
54
|
-
var undefs = [];
|
|
55
|
-
var infinities = [];
|
|
56
|
-
var bigInts = [];
|
|
57
|
-
var urls = [];
|
|
58
|
-
function replacer(key, value) {
|
|
59
|
-
if (options.ignoreFunction) deleteFunctions(value);
|
|
60
|
-
if (!value && void 0 !== value && value !== BigInt(0)) return value;
|
|
61
|
-
var origValue = this[key];
|
|
62
|
-
var type = typeof origValue;
|
|
63
|
-
if ('object' === type) {
|
|
64
|
-
if (origValue instanceof RegExp) return '@__R-' + UID + '-' + (regexps.push(origValue) - 1) + '__@';
|
|
65
|
-
if (origValue instanceof Date) return '@__D-' + UID + '-' + (dates.push(origValue) - 1) + '__@';
|
|
66
|
-
if (origValue instanceof Map) return '@__M-' + UID + '-' + (maps.push(origValue) - 1) + '__@';
|
|
67
|
-
if (origValue instanceof Set) return '@__S-' + UID + '-' + (sets.push(origValue) - 1) + '__@';
|
|
68
|
-
if (origValue instanceof Array) {
|
|
69
|
-
var isSparse = origValue.filter(function() {
|
|
70
|
-
return true;
|
|
71
|
-
}).length !== origValue.length;
|
|
72
|
-
if (isSparse) return '@__A-' + UID + '-' + (arrays.push(origValue) - 1) + '__@';
|
|
73
|
-
}
|
|
74
|
-
if (origValue instanceof URL) return '@__L-' + UID + '-' + (urls.push(origValue) - 1) + '__@';
|
|
75
|
-
}
|
|
76
|
-
if ('function' === type) return '@__F-' + UID + '-' + (functions.push(origValue) - 1) + '__@';
|
|
77
|
-
if ('undefined' === type) return '@__U-' + UID + '-' + (undefs.push(origValue) - 1) + '__@';
|
|
78
|
-
if ('number' === type && !isNaN(origValue) && !isFinite(origValue)) return '@__I-' + UID + '-' + (infinities.push(origValue) - 1) + '__@';
|
|
79
|
-
if ('bigint' === type) return '@__B-' + UID + '-' + (bigInts.push(origValue) - 1) + '__@';
|
|
80
|
-
return value;
|
|
81
|
-
}
|
|
82
|
-
function serializeFunc(fn) {
|
|
83
|
-
var serializedFn = fn.toString();
|
|
84
|
-
if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) throw new TypeError('Serializing native function: ' + fn.name);
|
|
85
|
-
if (IS_PURE_FUNCTION.test(serializedFn)) return serializedFn;
|
|
86
|
-
if (IS_ARROW_FUNCTION.test(serializedFn)) return serializedFn;
|
|
87
|
-
var argsStartsAt = serializedFn.indexOf('(');
|
|
88
|
-
var def = serializedFn.substr(0, argsStartsAt).trim().split(' ').filter(function(val) {
|
|
89
|
-
return val.length > 0;
|
|
90
|
-
});
|
|
91
|
-
var nonReservedSymbols = def.filter(function(val) {
|
|
92
|
-
return -1 === RESERVED_SYMBOLS.indexOf(val);
|
|
93
|
-
});
|
|
94
|
-
if (nonReservedSymbols.length > 0) return (def.indexOf('async') > -1 ? 'async ' : '') + 'function' + (def.join('').indexOf('*') > -1 ? '*' : '') + serializedFn.substr(argsStartsAt);
|
|
95
|
-
return serializedFn;
|
|
96
|
-
}
|
|
97
|
-
if (options.ignoreFunction && "function" == typeof obj) obj = void 0;
|
|
98
|
-
if (void 0 === obj) return String(obj);
|
|
99
|
-
var str;
|
|
100
|
-
str = options.isJSON && !options.space ? JSON.stringify(obj) : JSON.stringify(obj, options.isJSON ? null : replacer, options.space);
|
|
101
|
-
if ('string' != typeof str) return String(str);
|
|
102
|
-
if (true !== options.unsafe) str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars);
|
|
103
|
-
if (0 === functions.length && 0 === regexps.length && 0 === dates.length && 0 === maps.length && 0 === sets.length && 0 === arrays.length && 0 === undefs.length && 0 === infinities.length && 0 === bigInts.length && 0 === urls.length) return str;
|
|
104
|
-
return str.replace(PLACE_HOLDER_REGEXP, function(match, backSlash, type, valueIndex) {
|
|
105
|
-
if (backSlash) return match;
|
|
106
|
-
if ('D' === type) return "new Date(\"" + dates[valueIndex].toISOString() + "\")";
|
|
107
|
-
if ('R' === type) return "new RegExp(" + serialize(regexps[valueIndex].source) + ", \"" + regexps[valueIndex].flags + "\")";
|
|
108
|
-
if ('M' === type) return "new Map(" + serialize(Array.from(maps[valueIndex].entries()), options) + ")";
|
|
109
|
-
if ('S' === type) return "new Set(" + serialize(Array.from(sets[valueIndex].values()), options) + ")";
|
|
110
|
-
if ('A' === type) return "Array.prototype.slice.call(" + serialize(Object.assign({
|
|
111
|
-
length: arrays[valueIndex].length
|
|
112
|
-
}, arrays[valueIndex]), options) + ")";
|
|
113
|
-
if ('U' === type) return 'undefined';
|
|
114
|
-
if ('I' === type) return infinities[valueIndex];
|
|
115
|
-
if ('B' === type) return "BigInt(\"" + bigInts[valueIndex] + "\")";
|
|
116
|
-
if ('L' === type) return "new URL(" + serialize(urls[valueIndex].toString(), options) + ")";
|
|
117
|
-
var fn = functions[valueIndex];
|
|
118
|
-
return serializeFunc(fn);
|
|
119
|
-
});
|
|
120
|
-
};
|
|
121
|
-
},
|
|
122
|
-
crypto: function(module) {
|
|
123
|
-
"use strict";
|
|
124
|
-
module.exports = require("crypto");
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
var __webpack_module_cache__ = {};
|
|
128
|
-
function __webpack_require__(moduleId) {
|
|
129
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
130
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
131
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
132
|
-
exports: {}
|
|
133
|
-
};
|
|
134
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
135
|
-
return module.exports;
|
|
136
|
-
}
|
|
137
|
-
(()=>{
|
|
138
|
-
__webpack_require__.n = (module)=>{
|
|
139
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
140
|
-
__webpack_require__.d(getter, {
|
|
141
|
-
a: getter
|
|
142
|
-
});
|
|
143
|
-
return getter;
|
|
144
|
-
};
|
|
145
|
-
})();
|
|
146
|
-
(()=>{
|
|
147
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
148
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
149
|
-
enumerable: true,
|
|
150
|
-
get: definition[key]
|
|
151
|
-
});
|
|
152
|
-
};
|
|
153
|
-
})();
|
|
154
|
-
(()=>{
|
|
155
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
156
|
-
})();
|
|
157
|
-
(()=>{
|
|
158
|
-
__webpack_require__.r = (exports1)=>{
|
|
159
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
160
|
-
value: 'Module'
|
|
161
|
-
});
|
|
162
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
163
|
-
value: true
|
|
164
|
-
});
|
|
165
|
-
};
|
|
166
|
-
})();
|
|
167
|
-
var __webpack_exports__ = {};
|
|
168
|
-
(()=>{
|
|
169
|
-
"use strict";
|
|
170
|
-
__webpack_require__.r(__webpack_exports__);
|
|
171
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
172
|
-
PLUGIN_ASSETS_RETRY_NAME: ()=>PLUGIN_ASSETS_RETRY_NAME,
|
|
173
|
-
ASSETS_RETRY_DATA_ATTRIBUTE: ()=>ASSETS_RETRY_DATA_ATTRIBUTE,
|
|
174
|
-
pluginAssetsRetry: ()=>pluginAssetsRetry
|
|
175
|
-
});
|
|
176
|
-
const external_node_fs_namespaceObject = require("node:fs");
|
|
177
|
-
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
178
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
179
|
-
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
180
|
-
const external_node_url_namespaceObject = require("node:url");
|
|
181
|
-
const core_namespaceObject = require("@rsbuild/core");
|
|
182
|
-
var serialize_javascript = __webpack_require__("./node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js");
|
|
183
|
-
var serialize_javascript_default = /*#__PURE__*/ __webpack_require__.n(serialize_javascript);
|
|
184
|
-
function _define_property(obj, key, value) {
|
|
185
|
-
if (key in obj) Object.defineProperty(obj, key, {
|
|
186
|
-
value: value,
|
|
187
|
-
enumerable: true,
|
|
188
|
-
configurable: true,
|
|
189
|
-
writable: true
|
|
190
|
-
});
|
|
191
|
-
else obj[key] = value;
|
|
192
|
-
return obj;
|
|
193
|
-
}
|
|
194
|
-
const AsyncChunkRetryPlugin_dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__));
|
|
195
|
-
function modifyWebpackRuntimeModule(module, modifier) {
|
|
196
|
-
try {
|
|
197
|
-
const originSource = module.getGeneratedCode();
|
|
198
|
-
module.getGeneratedCode = ()=>modifier(originSource);
|
|
199
|
-
} catch (err) {
|
|
200
|
-
console.error('Failed to modify webpack RuntimeModule');
|
|
201
|
-
throw err;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
function modifyRspackRuntimeModule(module, modifier) {
|
|
205
|
-
try {
|
|
206
|
-
const originSource = module.source.source.toString();
|
|
207
|
-
module.source.source = Buffer.from(modifier(originSource), 'utf-8');
|
|
208
|
-
} catch (err) {
|
|
209
|
-
console.error('Failed to modify Rspack RuntimeModule');
|
|
210
|
-
throw err;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function modifyRuntimeModule(module, modifier, isRspack) {
|
|
214
|
-
if (isRspack) modifyRspackRuntimeModule(module, modifier);
|
|
215
|
-
else modifyWebpackRuntimeModule(module, modifier);
|
|
216
|
-
}
|
|
217
|
-
class AsyncChunkRetryPlugin {
|
|
218
|
-
getRawRuntimeRetryCode() {
|
|
219
|
-
const { RuntimeGlobals } = core_namespaceObject.rspack;
|
|
220
|
-
const filename = 'asyncChunkRetry';
|
|
221
|
-
const runtimeFilePath = external_node_path_default().join(AsyncChunkRetryPlugin_dirname, 'runtime', this.minify ? `${filename}.min.js` : `${filename}.js`);
|
|
222
|
-
const rawText = external_node_fs_default().readFileSync(runtimeFilePath, 'utf-8');
|
|
223
|
-
return rawText.replaceAll('__RUNTIME_GLOBALS_REQUIRE__', RuntimeGlobals.require).replaceAll('__RUNTIME_GLOBALS_ENSURE_CHUNK__', RuntimeGlobals.ensureChunk).replaceAll('__RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__', RuntimeGlobals.getChunkScriptFilename).replaceAll('__RUNTIME_GLOBALS_GET_CSS_FILENAME__', RuntimeGlobals.getChunkCssFilename).replaceAll('__RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__', '__webpack_require__.miniCssF').replaceAll('__RUNTIME_GLOBALS_RSBUILD_LOAD_STYLESHEET__', '__webpack_require__.rbLoadStyleSheet').replaceAll('__RUNTIME_GLOBALS_PUBLIC_PATH__', RuntimeGlobals.publicPath).replaceAll('__RUNTIME_GLOBALS_LOAD_SCRIPT__', RuntimeGlobals.loadScript).replaceAll('__RETRY_OPTIONS__', serialize_javascript_default()(this.runtimeOptions));
|
|
224
|
-
}
|
|
225
|
-
apply(compiler) {
|
|
226
|
-
compiler.hooks.thisCompilation.tap(this.name, (compilation)=>{
|
|
227
|
-
const isRspack = this.isRspack;
|
|
228
|
-
compilation.hooks.runtimeModule.tap(this.name, (module)=>{
|
|
229
|
-
const constructorName = isRspack ? module.constructorName : module.constructor?.name;
|
|
230
|
-
const isCssLoadingRuntimeModule = 'CssLoadingRuntimeModule' === constructorName;
|
|
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);
|
|
232
|
-
const isPublicPathModule = 'publicPath' === module.name || 'PublicPathRuntimeModule' === constructorName || 'AutoPublicPathRuntimeModule' === constructorName;
|
|
233
|
-
if (isPublicPathModule) {
|
|
234
|
-
const runtimeCode = this.getRawRuntimeRetryCode();
|
|
235
|
-
modifyRuntimeModule(module, (originSource)=>`${originSource}\n${runtimeCode}`, isRspack);
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
constructor(options, isRspack, minify){
|
|
241
|
-
_define_property(this, "name", 'ASYNC_CHUNK_RETRY_PLUGIN');
|
|
242
|
-
_define_property(this, "isRspack", void 0);
|
|
243
|
-
_define_property(this, "minify", void 0);
|
|
244
|
-
_define_property(this, "runtimeOptions", void 0);
|
|
245
|
-
this.runtimeOptions = options;
|
|
246
|
-
this.isRspack = isRspack;
|
|
247
|
-
this.minify = minify;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
const src_dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__));
|
|
251
|
-
const PLUGIN_ASSETS_RETRY_NAME = 'rsbuild:assets-retry';
|
|
252
|
-
const ASSETS_RETRY_DATA_ATTRIBUTE = 'data-rsbuild-assets-retry';
|
|
253
|
-
function getRuntimeOptions(userOptions, defaultCrossOrigin) {
|
|
254
|
-
const { inlineScript, minify, ...runtimeOptions } = userOptions;
|
|
255
|
-
const defaultOptions = {
|
|
256
|
-
max: 3,
|
|
257
|
-
type: [
|
|
258
|
-
'link',
|
|
259
|
-
"script",
|
|
260
|
-
'img'
|
|
261
|
-
],
|
|
262
|
-
domain: [],
|
|
263
|
-
crossOrigin: defaultCrossOrigin,
|
|
264
|
-
delay: 0,
|
|
265
|
-
addQuery: false
|
|
266
|
-
};
|
|
267
|
-
function normalizeOption(options) {
|
|
268
|
-
const result = {
|
|
269
|
-
...defaultOptions,
|
|
270
|
-
...options
|
|
271
|
-
};
|
|
272
|
-
if (!Array.isArray(result.type) || 0 === result.type.length) result.type = defaultOptions.type;
|
|
273
|
-
if (!Array.isArray(result.domain) || 0 === result.domain.length) result.domain = defaultOptions.domain;
|
|
274
|
-
if (Array.isArray(result.domain)) result.domain = result.domain.filter(Boolean);
|
|
275
|
-
return result;
|
|
276
|
-
}
|
|
277
|
-
if ('rules' in runtimeOptions) {
|
|
278
|
-
const result = runtimeOptions.rules.map((i)=>normalizeOption(i));
|
|
279
|
-
return result;
|
|
280
|
-
}
|
|
281
|
-
return [
|
|
282
|
-
normalizeOption(runtimeOptions)
|
|
283
|
-
];
|
|
284
|
-
}
|
|
285
|
-
async function getRetryCode(runtimeOptions, minify) {
|
|
286
|
-
const filename = 'initialChunkRetry';
|
|
287
|
-
const runtimeFilePath = external_node_path_default().join(src_dirname, 'runtime', minify ? `${filename}.min.js` : `${filename}.js`);
|
|
288
|
-
const runtimeCode = await external_node_fs_default().promises.readFile(runtimeFilePath, 'utf-8');
|
|
289
|
-
return runtimeCode.replace('__RETRY_OPTIONS__', serialize_javascript_default()(runtimeOptions));
|
|
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
|
-
}
|
|
294
|
-
const pluginAssetsRetry = (userOptions = {})=>({
|
|
295
|
-
name: PLUGIN_ASSETS_RETRY_NAME,
|
|
296
|
-
setup (api) {
|
|
297
|
-
const { inlineScript = true } = userOptions;
|
|
298
|
-
const getScriptPath = (environment)=>{
|
|
299
|
-
const distDir = environment.config.output.distPath.js;
|
|
300
|
-
return external_node_path_default().posix.join(distDir, "assets-retry.1-5-1.js");
|
|
301
|
-
};
|
|
302
|
-
const getDefaultValueFromRsbuildConfig = (config)=>{
|
|
303
|
-
const minify = 'boolean' == typeof config.output.minify ? config.output.minify : config.output.minify?.js;
|
|
304
|
-
return {
|
|
305
|
-
crossorigin: config.html.crossorigin,
|
|
306
|
-
minify: Boolean(minify) && 'production' === config.mode
|
|
307
|
-
};
|
|
308
|
-
};
|
|
309
|
-
if (inlineScript) api.modifyHTMLTags(async ({ headTags, bodyTags }, { environment })=>{
|
|
310
|
-
const { htmlPaths, config } = environment;
|
|
311
|
-
if ('web' === config.output.target && 0 === Object.entries(htmlPaths).length) logNoHtmlRegisterWaring();
|
|
312
|
-
const { minify, crossorigin } = getDefaultValueFromRsbuildConfig(config);
|
|
313
|
-
const runtimeOptions = getRuntimeOptions(userOptions, crossorigin);
|
|
314
|
-
const code = await getRetryCode(runtimeOptions, minify);
|
|
315
|
-
headTags.unshift({
|
|
316
|
-
tag: "script",
|
|
317
|
-
attrs: {
|
|
318
|
-
[ASSETS_RETRY_DATA_ATTRIBUTE]: 'inline'
|
|
319
|
-
},
|
|
320
|
-
children: code
|
|
321
|
-
});
|
|
322
|
-
return {
|
|
323
|
-
headTags,
|
|
324
|
-
bodyTags
|
|
325
|
-
};
|
|
326
|
-
});
|
|
327
|
-
else {
|
|
328
|
-
api.modifyHTMLTags(async ({ headTags, bodyTags }, { assetPrefix, environment })=>{
|
|
329
|
-
if ('web' === environment.config.output.target && 0 === Object.entries(environment.htmlPaths).length) logNoHtmlRegisterWaring();
|
|
330
|
-
const scriptPath = getScriptPath(environment);
|
|
331
|
-
const url = (0, core_namespaceObject.ensureAssetPrefix)(scriptPath, assetPrefix);
|
|
332
|
-
headTags.unshift({
|
|
333
|
-
tag: "script",
|
|
334
|
-
attrs: {
|
|
335
|
-
src: url,
|
|
336
|
-
[ASSETS_RETRY_DATA_ATTRIBUTE]: 'external'
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
return {
|
|
340
|
-
headTags,
|
|
341
|
-
bodyTags
|
|
342
|
-
};
|
|
343
|
-
});
|
|
344
|
-
api.processAssets({
|
|
345
|
-
stage: 'additional'
|
|
346
|
-
}, async ({ sources, compilation, environment })=>{
|
|
347
|
-
const { config } = environment;
|
|
348
|
-
if ('web' !== config.output.target) return;
|
|
349
|
-
const scriptPath = getScriptPath(environment);
|
|
350
|
-
const { crossorigin, minify } = getDefaultValueFromRsbuildConfig(config);
|
|
351
|
-
const runtimeOptions = getRuntimeOptions(userOptions, crossorigin);
|
|
352
|
-
const code = await getRetryCode(runtimeOptions, minify);
|
|
353
|
-
compilation.emitAsset(scriptPath, new sources.RawSource(code));
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
api.modifyBundlerChain(async (chain, { environment })=>{
|
|
357
|
-
const { config } = environment;
|
|
358
|
-
if ('web' !== config.output.target) return;
|
|
359
|
-
const { crossorigin, minify } = getDefaultValueFromRsbuildConfig(config);
|
|
360
|
-
const runtimeOptions = getRuntimeOptions(userOptions, crossorigin);
|
|
361
|
-
const isRspack = 'rspack' === api.context.bundlerType;
|
|
362
|
-
chain.plugin('async-chunk-retry').use(AsyncChunkRetryPlugin, [
|
|
363
|
-
runtimeOptions,
|
|
364
|
-
isRspack,
|
|
365
|
-
minify
|
|
366
|
-
]);
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
})();
|
|
371
|
-
exports.ASSETS_RETRY_DATA_ATTRIBUTE = __webpack_exports__.ASSETS_RETRY_DATA_ATTRIBUTE;
|
|
372
|
-
exports.PLUGIN_ASSETS_RETRY_NAME = __webpack_exports__.PLUGIN_ASSETS_RETRY_NAME;
|
|
373
|
-
exports.pluginAssetsRetry = __webpack_exports__.pluginAssetsRetry;
|
|
374
|
-
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
375
|
-
"ASSETS_RETRY_DATA_ATTRIBUTE",
|
|
376
|
-
"PLUGIN_ASSETS_RETRY_NAME",
|
|
377
|
-
"pluginAssetsRetry"
|
|
378
|
-
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
379
|
-
Object.defineProperty(exports, '__esModule', {
|
|
380
|
-
value: true
|
|
381
|
-
});
|