nuxt / components

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

feat: allow components to provide absolute import path #234

Open antfu opened 3 years ago

antfu commented 3 years ago

This would allow libraries to provide absolute import paths (from library submodules, or virtual modules) using the components:extend hook. In my case, I am integrating with unplugin-icons.

pi0 commented 3 years ago

I think it should still work by setting a relative path to node_modules. Are you using a virtual import pattern? An example would be nice :)

antfu commented 3 years ago

The import for unplugin-icons uses something like import Icon from '~icons/logos/nuxt-icon', which in the original behavior it will always prepend with ../ and got this error:

image

See https://github.com/antfu/unplugin-icons/pull/63 for the implementation.

This other case I can think about might be importing from some libraries, like: import Button from 'element-ui/lib/button'

As for the windows path resolution, I guess since the isAbsolute can only be provided by hooks, we can leave the responsibility to the module author?

pi0 commented 3 years ago

I'm mostly hesitating to see if we really need another component option or can actually fix the situation by default. For resolving ~, for instance we can check prefix to disable resolution on virtual and ~, @.

This other case I can think about might be importing from some libraries, like: import Button from 'element-ui/lib/button'

This case makes sense. But maybe with a flag like resolvePath: false ?

One more point, we usually allow inherit options from dirOptions (apply option to a group of scanned components) (https://github.com/antfu/unplugin-icons/pull/63#discussion_r709546061)

antfu commented 3 years ago

Do you mean we rename isAbsolute to resolvePath?

pi0 commented 3 years ago

Yes please, and also auto-enable the flag when ~, @ prefixes was provided if possible :)

jd-solanki commented 3 years ago

Sorry guys I don't want to disturb you here but I guess this is stale for a long time. Will this get updated?

Actually, I am waiting for this PR https://github.com/antfu/unplugin-icons/pull/63

Regards.

AqueleHaru commented 2 years ago

Still waiting too.