Closed EvgenyOrekhov closed 10 months ago
Hello @alexkramer98!
Would appreciate your input on default exports in Vue 3/Nuxt 3.
I can see at least one rule that requires you to use export default
- vue/require-direct-export
.
vue/require-direct-export
rule valid for single-file components only? Or for other types of components and Vue modules as well?export default
?import/no-default-export
rule for Vue 3/Nuxt 3 entirely, or only for some specific files/folders?Hi! Off the top of my head, the default export is only a convention in Vue files. For other files, such as composables, it's optional. This is the case for both Vue and Nuxt. There might be other exceptions that I'm overlooking right now so I'll try to get back to you about that tomorrow.
I haven't found any other exceptions when it comes to Vue. With Nuxt, for the server directory (api, middleware, routes, plugins), they do use a default export in the documentation, but not for server/utils
for example.
For both Vue and Nuxt, single file components can either be defined using the composition api or the options api. The composition api uses no export at all, and the options api uses a default export.
I would recommend to either disable import/no-default-export
for Vue/Nuxt all together, or to disable the rule for .vue
files and the server directory. I believe vue/require-direct-export
is appropriate where the default export is used.
export default
should be banned completely, but unfortunately many frameworks rely on it.Even though
import/no-default-export
rule remains disabled, I recommend avoiding default exports, if possible.Reasons:
.default
in some cases (like with dynamicimport()
)Ref #846 Ban default exports