Skip to content

Commit ea4cdd1

Browse files
committed
feat: support runtime.url to load multi type resource
1 parent 6270d39 commit ea4cdd1

File tree

3 files changed

+53
-13
lines changed

3 files changed

+53
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
See [https://github.com/ice-lab/icestark/releases](https://github.com/ice-lab/icestark/releases) for what has changed in each version of icestark.
44

5+
# 2.8.3
6+
7+
- [feat] support `runtime.url` as an array for loading multiple types of resources.
8+
59
# 2.8.2
610

711
- [fix] fix the issue that the UMD library is overwritten by undefined value.

packages/icestark/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ice/stark",
3-
"version": "2.8.2",
3+
"version": "2.8.3",
44
"description": "Icestark is a JavaScript library for multiple projects, Ice workbench solution.",
55
"scripts": {
66
"build": "rm -rf lib && tsc",

packages/icestark/src/apps.ts

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Sandbox, { SandboxConstructor, SandboxProps } from '@ice/sandbox';
22
import isEmpty from 'lodash.isempty';
3-
import { NOT_LOADED, NOT_MOUNTED, LOADING_ASSETS, UNMOUNTED, LOAD_ERROR, MOUNTED } from './util/constant';
3+
import { NOT_LOADED, NOT_MOUNTED, LOADING_ASSETS, UNMOUNTED, LOAD_ERROR, MOUNTED, IS_CSS_REGEX } from './util/constant';
44
import findActivePathCurry, { ActivePath, PathOption, formatPath } from './util/checkActive';
55
import {
66
createSandbox,
@@ -44,7 +44,7 @@ export interface ModuleLifeCycle {
4444
}
4545

4646
export interface RuntimeConfig {
47-
url: string;
47+
url: string | string[];
4848
library: string;
4949
version: string;
5050
}
@@ -214,21 +214,57 @@ export async function loadAppModule(appConfig: AppConfig) {
214214
// Not to handle script element temporarily.
215215
break;
216216
case 'fetch': {
217-
await loadAndAppendCssAssets(appAssets.cssList, {
218-
cacheCss,
219-
fetch,
220-
});
217+
const runtimeCssList = [];
218+
const runtimeJsList = [];
221219
// Filter and map runtime libraries that haven't been registered in window
222220
const runtimeLibs = runtime?.filter((config) => {
223221
return config.version && config.library && !window[`${config.library}@${config.version}`];
224-
}).map((config) => ({
225-
content: config.url,
226-
type: AssetTypeEnum.RUNTIME,
227-
library: config.library,
228-
version: config.version,
229-
})) || [];
222+
}).map((config) => {
223+
// Handle both string and array URL formats
224+
const urls = Array.isArray(config.url) ? config.url : [config.url];
225+
// Separate CSS and JS URLs
226+
const jsUrls = [];
227+
urls.forEach((configUrl) => {
228+
if (IS_CSS_REGEX.test(configUrl)) {
229+
runtimeCssList.push({
230+
content: configUrl,
231+
type: AssetTypeEnum.EXTERNAL,
232+
});
233+
} else {
234+
jsUrls.push(configUrl);
235+
}
236+
});
237+
if (jsUrls.length === 0) {
238+
return null;
239+
}
240+
// Use the last JS URL as the main runtime JS
241+
const mainJs = jsUrls[jsUrls.length - 1];
242+
const restJs = jsUrls.slice(0, -1);
243+
restJs.forEach((configUrl) => {
244+
runtimeJsList.push({
245+
content: configUrl,
246+
type: AssetTypeEnum.EXTERNAL,
247+
});
248+
});
249+
250+
return {
251+
content: mainJs,
252+
type: AssetTypeEnum.RUNTIME,
253+
library: config.library,
254+
version: config.version,
255+
};
256+
}).filter(Boolean) || [];
257+
258+
await loadAndAppendCssAssets([
259+
...appAssets.cssList || [],
260+
...runtimeCssList,
261+
], {
262+
cacheCss,
263+
fetch,
264+
});
230265

231266
lifecycle = await loadScriptByFetch([
267+
...runtimeJsList,
232268
...runtimeLibs,
233269
...appAssets.jsList,
234270
], appSandbox, fetch);

0 commit comments

Comments
 (0)