-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow named export instead of default export for components #14806
Comments
I'm not openly against something like this. I just wonder about the reasons. For deprecating: This should be mainly a concern for libraries, not projects. Projects don't share stuff with other projects, that's the job of libraries. In libraries, you usually export using named exports in the NPM package's True, maybe it is better/more accurate to be able to do a "global rename" command, but I bet "Replace in files..." is almost as good. Finally, trying to force a particular name on consumers is an opinion, and I believe it is Svelte's mission to be as unopinionated as possible. It is an opinion because it is not a performance hit, using Other than the above, I'd be OK with this, so long the default export is an option. I don't feel like changing it. If this is an opt-in feature, fine by me. |
You can also re-export it from the script module <script module>
export {default as whatever} from './same-file.svelte'
</script> |
@webJose My use case are just in projects, it happens that you need to create a v2 component to not cause regressions everywhere in the project
@Thiagolino8 This is interesting, vscode auto-import may get a bit confusing since you don't know if you are importing the named or the default export. |
I am also not a fan of default imports/exports. If this feature is added it probably belongs in <svelte:options export="MyComponent" /> People use all sorts of file names (e.g. |
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)It's a little bit annoying, and it would be cool to have a more sveltish way of doing it, perhaps something like this:
It would take the name of the file and export a symbol with the same value.
An alternative syntax can be:
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 likeDescribe the proposed solution
Above
Importance
nice to have
The text was updated successfully, but these errors were encountered: