-
Notifications
You must be signed in to change notification settings - Fork 134
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
Tree Shaking - automatically detecting usage #233
Comments
@EtienneBruines are you using Babel? |
Haven't had the need. Rollup for me personally. |
So what mechanism would be able to dynamically identify icons used (and do so in complex situations where methods or computed props are called to get icons)? |
Any mechanism that would be made as part of this feature request. For static icons that should be achievable? Even :icon usages that don't include variables (array syntax) would be doable. Without knowledge about HTML even regex would be able to find and detect those usages, dynamically importing it. That script can then be part of the webpack or Rollup build process. Since you asked about babel, does that mean babel can already do this? |
I agree, it is kinda hard to maintain a huge list of used icons while it could be automated. |
@robmadole is it possible to call import icon & library.add() inside a vue component? |
Did you have any luck with this? |
Even something like requiring the prefix would be preferable: I see the React library follows the same pattern. I'm a little curious as to the reasoning behind the suggested method of passing around [string,string] everywhere for an icon, vs a kebabed name. The split is negligibly cheap and it simplifies the code immensely. And the parsing on the library side could be non-existent if the objects stored that name instead of 2 separate fields Requiring it be prefaced with (fas|fal|far|fad) also should remove any barrier from the library being able to build up the library on its own. Or even if it was If I want to just put a square:
It's just too much imho for something that could be handled by the library and turned into:
I've found it to be polluting my code base tbh. Every Vue files script tag is littered with 2 imports and a library call minimum just to have an icon somewhere. Would love to see this simplified somehow. |
Agreed. Additionally, in your case, you could just create a component that accepts those attributes and get away with it :) Example:
then calling it from any other components with: |
Might just do that, it will at least help with the arrays everywhere, the only downside being having to pass through all the other props. Excited to see what they have planned for 6, hopefully it tackles this. To me the bigger pain is the imports and library call anywhere you want to use an icon. (Yes I could centralize it to a single file but then you have to do book keeping and if you change or delete an icon somewhere you have to do code base garbage collection making sure there's no other references) so doing it in place everywhere it's used is surprisingly the more manageable option. |
Lmao, I was about to quote all of the above, thankfully I wasn't lazy enough to edit the quotation. Yeah well, you only have to set up the component once and make it global, it will act like a shim or proxy or whatever you want to call it. you can find the props here: https://github.com/FortAwesome/vue-fontawesome/blob/2.x/src/components/FontAwesomeIcon.js You can have my little template, the rest you can complete from that file I have linked
As for manually importing icons for treeshaking, yeah well, it is indeed annoying but I have managed to successfully write an auto build script that would walk through all of my vue files, extract the icon names from them and autogenerate a fontawesome-autogen.js file which is basically importable. The script is about 115 lines, I will have it published in my repo once I'm done with it. |
Okay, as promised, here's my repository https://github.com/GTANAdam/vue-fontawesome-autogen |
While I agree it's better to import each icon you are using, you still can have unused icons ended up in the bundle Have you tried Tailwindcss? Now If only Fontawesome can do this as well. GTANAdam wrote a plugin to do this when doing |
Looking at the recommended usage
src/main.js
src/App.vue
And then the tree shaking docs:
Is your feature request related to a problem? Please describe.
Having to call
library.add(faCoffee)
is a pain. Using about 80 icons in a bigger project, keeping this up-to-date isn't nice.Describe the solution you'd like
Shouldn't the usage like
<font-awesome-icon icon="user-secret" />
suffice to be able to dynamically import only those icons? Especially when using webpack/rollup to parse it.Describe alternatives you've considered
N/A
Additional context
N/A
The text was updated successfully, but these errors were encountered: