Skip to content

Allow named export instead of default export for components #14806

@raythurnvoid

Description

@raythurnvoid

Describe the problem

Today in order to use named export with .svelte components we have to create a separate .ts file and re-export the component and perhaps the type of the Props (just to import all stuff from the same module)

export { default as Heading100 } from './Heading100.svelte';
export type { Heading100Props } from './Heading100.svelte';

It's a little bit annoying, and it would be cool to have a more sveltish way of doing it, perhaps something like this:

<script lang="ts" named-export>

It would take the name of the file and export a symbol with the same value.

An alternative syntax can be:

<script lang="ts" export="MyComponent">

Another approach would be a configuration in the svelte.config.js.

Why?

It helps refactoring and code maintainability.

Let's say you want to deprecate a component and you want to change its name to something like MyComponentOld, it's frustrating that the component would still appear in the templates as <MyComponent /> and there's no way to do a global rename with refactoring tool, so the only option is text search and replace.

It helps maintainability because you ensure that in most of the cases the tag used in the templates matches the component name unless explicitly renamed with as, sometime unorganized devs write stuff like

import Button from '$lib/component/SparklingButton.svelte';
import Button2 from '$lib/components/BorderedButton.svelte';

Describe the proposed solution

Above

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions