-
-
Notifications
You must be signed in to change notification settings - Fork 146
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
feat: support @nuxt/components auto-import #63
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
<template> | ||
<div class="markdown-body" style="padding: 2em 3em"> | ||
<logo-nuxt style="font-size:2em" /> | ||
<i-logos-nuxt-icon style="font-size:2em" /> | ||
<br> | ||
<p> | ||
Icons | ||
<MdiStore24Hour /> | ||
<IMdiStore24Hour /> | ||
<MdiAlarmOff /> | ||
from <code>unplugin-icons</code> | ||
</p> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import LogoNuxt from '~icons/logos/nuxt-icon' | ||
import MdiStore24Hour from '~icons/mdi/store-24-hour' | ||
import MdiAlarmOff from '~icons/mdi/alarm-off' | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Components module is supposed to to glob on added directories. Why are you doing it manually? 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In https://github.com/antfu/unplugin-vue-components we are scanning for components usages on each request, meaning that if you use a component like this:
In that case, we will know that the Alarm icon from MDI is used, and inject the import statement to it. While with
@nuxt/components
, we need to search for the components usage beforehand as we register them globally on dev. This is indeed an workaround, but do you see any better solution for that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hook is components:dirs
components:extend
was mainly added to fine-tune scanned components (IE if generated names need a change) and also exposing multiple components from same export (which i guess you have 1 file per component)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what I need is kinda another way around, I need to scan the usage of the components used instead of the components to be imported.
components:dirs
might not work for me as the icons aren't actually exist in the filesystem.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the same for nuxt build. Loader that scans usage is intentionally disabled on development as the cost of this scanning step was proven to be more and not scalable as the number of
.vue
files and components increases. One can force this behavior in dev by settingloader: true
in the components option.Can't we simply register all unplugin-vue components beforehand to Components module and let it lazy-load them in dev with
isAsync: true
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another point: There is runtime usage where the scanner cannot basically detect them by usage. Markdown (docus/content) is one example that is rendered after build step :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While in this case, Iconify has 10,000+ icons from over 100 icon sets. We certainly don't want to register them all 😅 and that's why we go with this on-demand approach.
Yes, this is indeed we are doing the same thing with the loader and I understand the tradeoff in dev here. If you don't mind to have an additional hook in the loader, we could have the on-demand resolution for loader, and fallback to this solution when the loader is not enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enabling loader if one of dirs requires it, would be nice idea indeed :) Would you please make an Issue+PR?