diff --git a/src/builder/rollup.ts b/src/builder/rollup.ts index 9a605525..d6117b86 100644 --- a/src/builder/rollup.ts +++ b/src/builder/rollup.ts @@ -319,6 +319,7 @@ const getChunkFilename = ( }; export function getRollupOptions(ctx: BuildContext): RollupOptions { + const _aliases = resolveAliases(ctx); return ({ input: Object.fromEntries( ctx.options.entries @@ -361,6 +362,7 @@ export function getRollupOptions(ctx: BuildContext): RollupOptions { ].filter(Boolean), external(id) { + id = resolveAlias(id, _aliases); const pkg = getpkg(id); const isExplicitExternal = arrayIncludes(ctx.options.externals, pkg) || @@ -402,7 +404,7 @@ export function getRollupOptions(ctx: BuildContext): RollupOptions { ctx.options.rollup.alias && alias({ ...ctx.options.rollup.alias, - entries: resolveAliases(ctx), + entries: _aliases, }), ctx.options.rollup.resolve && @@ -470,6 +472,16 @@ function resolveAliases(ctx: BuildContext) { return aliases; } +// TODO: use pathe utils to handle nested aliases +function resolveAlias(id: string, aliases: Record): string { + for (const [find, replacement] of Object.entries(aliases)) { + if (id.startsWith(find)) { + return id.replace(find, replacement); + } + } + return id; +} + export function _watch(rollupOptions: RollupOptions) { const watcher = rollupWatch(rollupOptions);