diff --git a/.changeset/many-turtles-move.md b/.changeset/many-turtles-move.md new file mode 100644 index 0000000000..7d699882c0 --- /dev/null +++ b/.changeset/many-turtles-move.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Allow renaming for default import components diff --git a/packages/astro/src/build/page.ts b/packages/astro/src/build/page.ts index ae472e0719..1f0093271e 100644 --- a/packages/astro/src/build/page.ts +++ b/packages/astro/src/build/page.ts @@ -222,14 +222,19 @@ async function gatherRuntimes({ astroConfig, buildState, filepath, logging, reso for (const componentImport of componentImports) { const importUrl = componentImport.source.value; const componentType = path.posix.extname(importUrl); - const componentName = path.posix.basename(importUrl, componentType); - const plugin = extensions[componentType] || defaultExtensions[componentType]; - plugins.add(plugin); - components[componentName] = { - plugin, - type: componentType, - specifier: importUrl, - }; + for (const specifier of componentImport.specifiers) { + if (specifier.type === 'ImportDefaultSpecifier') { + const componentName = specifier.local.name; + const plugin = extensions[componentType] || defaultExtensions[componentType]; + plugins.add(plugin); + components[componentName] = { + plugin, + type: componentType, + specifier: importUrl, + }; + break; + } + } } const dynamic = await acquireDynamicComponentImports(plugins, resolvePackageUrl); diff --git a/packages/astro/test/fixtures/astro-dynamic/src/pages/default-rename.astro b/packages/astro/test/fixtures/astro-dynamic/src/pages/default-rename.astro new file mode 100644 index 0000000000..8d418fc151 --- /dev/null +++ b/packages/astro/test/fixtures/astro-dynamic/src/pages/default-rename.astro @@ -0,0 +1,12 @@ +--- +import CounterRenamed from '../components/Counter.jsx'; +import SvelteCounterRenamed from '../components/SvelteCounter.svelte'; +--- + +Dynamic pages + + + + + +