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
Prod ready #6
Prod ready #6
Conversation
Hi @M1CK431, This looks awesome! Thank you :) |
@M1CK431 Cheers mate, I agree with all of the changes you've made here. @GTANAdam I understand it may not be your intended design pattern, but I agree that this package should not stray from the official/intended Font Awesome syntax. I had to fork and modify your work for the very reason identified by @M1CK431 --- it meant a significant amount of code change to adopt your proposed custom syntax. By maintaining the official syntax, you make it easy for a developer to introduce this package into their project, especially when considering an established/large project. I would encourage you to adopt this proposed change. |
Greetings, thank you for the contributions. I would also like to note that, the use of the official vue-fontawesome syntax goes against the main idea of this project. I suggest we have compatibility for both syntaxes. |
Hi @GTANAdam , Thanks for your reply. Perhaps I misunderstood what is the "main idea of this project" but from the README:
And so there is nothing about a custom syntaxe. Also, please notice the reason why the array syntaxe is needed: https://github.com/FortAwesome/vue-fontawesome#why-so-explicit-the-iconfar-coffee-syntax Anyway, It's very easy to handle the custom syntaxe, just by updating the regex in |
@GTANAdam I have updated this PR to add a way (environnement variable) to handle any custom syntaxe you wish simply by overriding the pattern used to match font awesome icons in the project. I have added an example in the README. Also, I have rewrite your From the updated README: CustomizationSometimes you may want to customize the pattern used to match font awesome icons in your projet. Wrapper example ( <template>
<FontAwesomeIcon :icon="faIcon" v-bind="$attrs" v-on="$listeners" />
</template>
<script>
export default {
props: { icon: { type: String, required: true } },
computed: {
faIcon: ({ icon }) => {
const [, style, name] = icon.match(/(fa[a-z])-([a-z-]+)/);
return [style, name];
}
}
};
</script> In that situation, a font awesome icon will looks like pattern="['\"](fa[a-z])-([a-z-]+)['\"]" npm explore @adambh/vue-fontawesome-autogen -- npm run gen or (for the automated version): var WebpackBeforeBuildPlugin = require('before-build-webpack');
// ...
module: {
plugins: [
new WebpackBeforeBuildPlugin(function(stats, callback) {
const {execSync} = require('child_process');
console.log(execSync(
'npm explore @adambh/vue-fontawesome-autogen -- npm run gen',
{ env: { pattern: `['"](fa[a-z])-([a-z-]+)['"]` } }
).toString());
callback();
}, ['run', 'watchRun'])
]
},
// ... -------------------------------------------------------------8<------------------------------------------------------------- |
@M1CK431 Greetings! My apologies for the late response as I have just checked my email inbox. cheers! |
Hi @GTANAdam, |
Greetings @M1CK431
Based on the stated above, I have concluded that the following points would solve multiple problems and keep everyone happy:
Once we have the changes on par with the stated requirements, the pull request will be merged with master. |
@M1CK431 Would you consider releasing your package to NPM? I think there is a fundamental difference of opinion here, and the code change is substantive enough that I believe it would be worth while, as opposed to trying to reconcile the two projects. |
Hi @phuze, As far as possible, I prefer to avoid forking a project because I think it's better for the open source community to works all together on a single project instead of wasting time and resource on multiple projects which reach the same goal. However, after the last comment of @GTANAdam, I'm thinking about it very seriously, because IMHO I have handled the need of @GTANAdam to deal with custom syntaxe (and even I have provided a better implementation of the custom component in the README, despite I'm personally against it). Now @GTANAdam you have to take a decision:
Please @GTANAdam it's not a big deal to add an env var... In addition it's well documented in the README... 🙏 @phuze My own deadline for this decision is around the end July. |
Greetings @M1CK431, I do agree with you on the fact that collaborating would solve fragmentation issues but I disagree on the fact that a PR should decide the future of the project by a submission of one sided solutions. here are a couple of reasons why and what we should stick to in order to solve issues.
I personally use this tool in my projects and I am not willing to break changes for cosmetical purposes. |
Hi @GTANAdam , I'm a bit surprised about that "fear" of the breaking change. I have provided clear instruction to easily handle it. In your case it means:
And so it should take less than 5 minutes. I can't agree with your point of "one sided solution" because I have added an easy way to handle custom syntaxe (with example in the README). From my point of view, the "futur of the project" is decided every time a contributor make a PR (in fact it's exactly what we are doing right now 😉).
Here is the root issue I guess. IMHO a lib like this one should handle the official
AFAIK, never, never in the "Vue community demand" there is something about handling a custom syntaxe. To conclude, you don't want to be annoyed for cosmetical purposes? Others think the same about there projects! So please, don't "force" everyone to use a custom syntaxe while the "Vue community demand" is only about managing imported fontawesome icons 🙏 |
Hey @M1CK431, Alright, so about the custom syntax.. I personally do not like the vue-fontawesome's syntax, so I decided to go with the vanilla fontawesome's way which, in my opinion, is much better. But okay, I get it, different tastes, different approaches, we should have an easy way to have both worlds existing at once without forgetting that the goal is to maintain compatibility which means, no breaking changes and updating should be 0-config. So, here's the following propositions:
|
Hi @GTANAdam ,
I'm really happy to read that, thanks!
I'm align with you and to be honest I was not very happy nor convince when font awesome made this change, but in fact our personal opinion doesn't matter here. Because we haven't the power to change the official syntaxe, we have to follow 🤷♂️ Now let's speak about your proposition:
s = `<fa :icon="['fad', 'trash']" class="mt-1" />` // sample string using official syntaxe
re = new RegExp(/['"](fa[a-z])-([a-z-]+)['"]|\[['"](fa[a-z])['"], *['"]([a-z-]+)['"]\]/, "g") // your proposition
re2 = new RegExp(/\[['"](fa[a-z])['"], *['"]([a-z-]+)['"]\]/, "g") // current implementation
console.log([...s.matchAll(re)][0])
["['fad', 'trash']", undefined, undefined, "fad", "trash", index: 11, input: "<fa :icon=\"['fad', 'trash']\" class=\"mt-1\" />", groups: undefined]
console.log([...s.matchAll(re2)][0])
["['fad', 'trash']", "fad", "trash", index: 11, input: "<fa :icon=\"['fad', 'trash']\" class=\"mt-1\" />", groups: undefined] As you can see, important values (
For all these reasons, I have handle your request of custom syntaxe support with an env var in the webpack config. I hope I have convinced you of the benefits of this method, despite the slight breaking change it implies. |
Greets @M1CK431,
This is irrelevant, performance isn't the critical aspect of this tool and nor it would cause any noticeable lag with the worst possible regex code
Well, that's due to different groupings of matches, I couldn't figure out a better way to have the regex output the same groups for different combinations at the moment, I'll look into it again later. for now, this can be trivially fixed by filtering the array. const s = `<fa :icon="['fad', 'trash']" class="mt-1" />`;
const re = new RegExp(/['"](fa[a-z])-([a-z-]+)['"]|\[['"](fa[a-z])['"], *['"]([a-z-]+)['"]\]/, "g");
console.log([...s.matchAll(re)][0]);
// result: [ "['fad', 'trash']", undefined, undefined, "fad", "trash" ]
console.log([...s.matchAll(re)][0].filter(e => e != null));
// result: [ "['fad', 'trash']", "fad", "trash" ] |
And what about point 3 and 4? |
Sure, as long as those introductions are optional, it's always welcome! |
Ok so, just to be sure, your requested change now are:
After that you will merge this PR? |
If it fits the previously discussed requirements, then I would have no reason not to merge the PR 🤷 |
You will still need to add a (very small, provided in README) component in your code base so it's a (kind of) breaking change. |
What component exactly? As far as I'm aware, with the improved regex, the vue-fontawesome syntax requires no shim to operate and for the normal fontawesome syntax, it requires the Fa.vue shim component. that's the difference. So including the imported component can be optional. |
It's not about parsing, it's the component used to transform the custom syntaxe to the official one. Please read the "Customization" section already provided here. |
Almost complete rewrite to make this package prod ready.
Changes compare to original version:
🆕 Automagically handle all installed styles, even the one which will be created in the futur (as long as font awesome keep the same naming pattern 🤞)
🆕 Detect used icons even in
.js
files (previously only.vue
files was handled, useful for computed icon 🎉 )🆕 Warn in console about unknown icon (for example if trying to use the
regular
style but don't have it installed)🆕 Could be used in
watch
mode (fix #1)🆕 Compatible with existing project (by using directly the regular
vue-fontawesome
component) - *see Breaking change below🚀 About 50% faster
This new rewritten version don't provide a custom
Fa.vue
component and so the previous syntaxe<fa icon="fas-check">
will not work out of the box anymore. Instead, you should use the regularvue-fontawesome
provided component (akaFontAwesomeIcon
).But if you absolutely want to keep the previous custom syntaxe (despite there is good reasons to use the regular one), you can override the default pattern used to match font awesome icons in your projet using an environnement variable. A complete example of how to do it is provided in the updated README, among a custom component example.
Despite it's a (kind of) breaking change, it will be hugely simpler to use this package in an existing projet which already use the regular component.
However, a (slight) change is still required in the code base of an existing project which want to use this new version. Check the README for details (#noTeaser 🤫).
How it works
This rewritten version does the following steps:
package.json
file to detect which font awesome styles are available in your project.vue
and.js
files in yoursrc
folder naively looking for font awesome icon definitions (must by an array with explicit prefix)src/plugins/fontawesome-autogen.js
(only if needed - aka icon added/removed in project 😎)Benefits compare to original
fas
style).js
files (useful for generated list based on an array/object/whatever imported from a.js
file)watchRun
mode