nuxt / components

Scan and auto import components for Nuxt.js 2.13+
MIT License
887 stars 48 forks source link

Alternative to `Lazy*` prefix #180

Open pi0 opened 3 years ago

pi0 commented 3 years ago

As mentioned by @dmx374 (#83), using Lazy prefix might be confusing in situations when the component name is prefixed with Lazy for its purpose (LazyLoad, LazySpin, etc).

We cannot use directives since it forces to use a loader and parsing overhead but we can introduce another alias while keeping backward compatibility with Lazy{name}. Some options:

pi0 commented 3 years ago

/cc @nuxt/framework ideas welcome

clarkdo commented 3 years ago

+1 for async for aligning to Vue async component https://v3.vuejs.org/guide/migration/async-components.html#_3-x-syntax https://v3.vuejs.org/guide/component-dynamic-async.html#async-components

pi0 commented 3 years ago

@clarkdo You mean <Async{Name}> option? It makes sense to be consistent with vue docs.

clarkdo commented 3 years ago

Yes

drewbaker commented 3 years ago

Maybe I’m misunderstand async components, but isn’t there lots of scenarios where a component can be used in different places, sometimes async and sometimes not? So by using the filename as the way to detect if it’s async or not seems like the wrong approach? Or is this the only way?

The Vue guide also recommend tightly coupled components to have related names, like “CarsList” and “CarsListItem”, so by forcing “Async” at the start of the component you’ll be loosing that coupling.

I just suspect people hate being forced to have any word in their component file name, no matter what you pick. That’s why I prefer the modifier Name.async.vue, feel more “nuxt” (like the way plugin file names can have client or server in them).

pi0 commented 3 years ago

@drewbaker That's true and you do don't need to prefix your component file name with either Lazy or Async 🙈 It should be called Foo.vue. <LazyFoo> is an alias to tell import Foo.vue as an async component.

drewbaker commented 3 years ago

Oh Ok I’m that case AsyncFoo seems great!

Bigdragon13th commented 3 years ago

@pi0 I come across this issue since I just found out Nuxt having this as default now on new projects setup. And looking in the doc I too thought I have to rename my component Lazy{Name} to make it lazy load, I'm happy it's not the case. Maybe clarify this in doc would help?