|
1 | 1 | import Sandbox, { SandboxConstructor, SandboxProps } from '@ice/sandbox'; |
2 | 2 | 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'; |
4 | 4 | import findActivePathCurry, { ActivePath, PathOption, formatPath } from './util/checkActive'; |
5 | 5 | import { |
6 | 6 | createSandbox, |
@@ -44,7 +44,7 @@ export interface ModuleLifeCycle { |
44 | 44 | } |
45 | 45 |
|
46 | 46 | export interface RuntimeConfig { |
47 | | - url: string; |
| 47 | + url: string | string[]; |
48 | 48 | library: string; |
49 | 49 | version: string; |
50 | 50 | } |
@@ -214,21 +214,57 @@ export async function loadAppModule(appConfig: AppConfig) { |
214 | 214 | // Not to handle script element temporarily. |
215 | 215 | break; |
216 | 216 | case 'fetch': { |
217 | | - await loadAndAppendCssAssets(appAssets.cssList, { |
218 | | - cacheCss, |
219 | | - fetch, |
220 | | - }); |
| 217 | + const runtimeCssList = []; |
| 218 | + const runtimeJsList = []; |
221 | 219 | // Filter and map runtime libraries that haven't been registered in window |
222 | 220 | const runtimeLibs = runtime?.filter((config) => { |
223 | 221 | 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 | + }); |
230 | 265 |
|
231 | 266 | lifecycle = await loadScriptByFetch([ |
| 267 | + ...runtimeJsList, |
232 | 268 | ...runtimeLibs, |
233 | 269 | ...appAssets.jsList, |
234 | 270 | ], appSandbox, fetch); |
|
0 commit comments