components icon indicating copy to clipboard operation
components copied to clipboard

feat: allow components to provide absolute import path

Open antfu opened this issue 2 years ago • 7 comments

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.

antfu avatar Sep 15 '21 19:09 antfu

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 :)

pi0 avatar Sep 15 '21 20:09 pi0

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?

antfu avatar Sep 15 '21 20:09 antfu

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)

pi0 avatar Sep 15 '21 20:09 pi0

Do you mean we rename isAbsolute to resolvePath?

antfu avatar Sep 15 '21 20:09 antfu

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

pi0 avatar Sep 15 '21 20:09 pi0

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.

jd-solanki avatar Oct 29 '21 12:10 jd-solanki

Still waiting too.

AqueleHaru avatar Jul 17 '22 16:07 AqueleHaru