diff --git a/src/lib/bundle/core.ts b/src/lib/bundle/core.ts index 8b1f3fa..541d25e 100644 --- a/src/lib/bundle/core.ts +++ b/src/lib/bundle/core.ts @@ -160,6 +160,19 @@ function replaceRequiredImportSource( ); } +function replaceRemoteRspackRelativeImportSources(source: string, version: string) { + return source.replace( + /\b(from\s*|import\s*)["'](\.\/[^"']+\.(?:mjs|js))["'];?/g, + (match, prefix: string, specifier: string) => { + try { + return `${prefix}${JSON.stringify(getRspackBrowserFileUrl(version, `dist/${specifier.slice(2)}`))};`; + } catch { + return match; + } + }, + ); +} + function hasImportSource(source: string, specifier: string) { return new RegExp(`from\\s*["']${escapeRegExp(specifier)}["'];?`).test(source); } @@ -301,6 +314,7 @@ async function getRspackBrowserEntryUrls(version: string): Promise