Closed xfuturomax closed 4 months ago
If you didn't import the ShareIconsModule
it will not import the default share icons.
It could be you are importing icons some where in your project, or your project isn't tree-shaking the imports.
Try to import each icons individually like:
import { faCheck } from '@fortawesome/free-solid-svg-icons/fa-check';
import { faLink } from '@fortawesome/free-solid-svg-icons/fa-link';
instead of
import { faLink, faCheck } from '@fortawesome/free-solid-svg-icons';
If you didn't import the ShareIconsModule it will not import the default share icons.
Sorry, here don't follow. My component works perfectly with this library. Now, I just want to decrease the size of Fortawesome.
It could be you are importing icons some where in your project, or your project isn't tree-shaking the imports.
No, it was the first thing that I checked. My code is in the first message.
your project isn't tree-shaking the imports.
Also no, it's default angular v16 project with aot=true by default 🤷
Try to import each icons individually like:
I'll try it, thank you.
Yes, it helped, thanks: But why is tree-shaking not working? The same was true with lodash, so I had to explicitly import each function.
I am not sure why, I heard tree-shaking works since even older versions of Angular, but maybe it works for production build only.
But for analyzer I use production build:
ng build --configuration production --stats-json && ./node_modules/.bin/webpack-bundle-analyzer dist/browser/stats.json
🤔
Anyway, thanks for the help; I'll try to figure out what can cause this issue with tree shaking. Maybe it's a problem of webpack-bundle-analyzer
Sorry @MurhafSousli to raise the topic again; I don't want to create a new topic. I'm trying to update to the new Angular v17 and also updated to share buttons v14. Conditions are the same. And after analyzing webpack, the issue came back.
This is new code:
import { ShareButtons } from 'ngx-sharebuttons/buttons';
import { FaIconLibrary } from '@fortawesome/angular-fontawesome';
import { faFacebookF } from '@fortawesome/free-brands-svg-icons/faFacebookF';
import { faRedditAlien } from '@fortawesome/free-brands-svg-icons/faRedditAlien';
import { faTelegramPlane } from '@fortawesome/free-brands-svg-icons/faTelegramPlane';
import { faXTwitter } from '@fortawesome/free-brands-svg-icons/faXTwitter';
import { faWhatsapp } from '@fortawesome/free-brands-svg-icons/faWhatsapp';
import { faCheck } from '@fortawesome/free-solid-svg-icons/faCheck';
import { faLink } from '@fortawesome/free-solid-svg-icons/faLink';
const shareIcons = [
faWhatsapp,
faXTwitter,
faRedditAlien,
faFacebookF,
faTelegramPlane,
faLink,
faCheck,
];
export class AppModule {
constructor(iconLibrary: FaIconLibrary) {
iconLibrary.addIcons(...shareIcons);
}
}
<share-buttons
[theme]="'circles-dark'"
[include]="['whatsapp','x','reddit','facebook','telegram','copy']"
[show]="6"
></share-buttons>
I don't use:
customShareButton('facebook', {
color: 'orange'
})
and style import.
I tried to specify custom settings, but it doesn't help:
provideShareButtonsOptions(
// Override facebook icon
customShareButton('whatsapp', {
icon: faWhatsapp
}),
customShareButton('facebook', {
icon: faFacebookF
}),
customShareButton('x', {
icon: faXTwitter
}),
customShareButton('reddit', {
icon: faRedditAlien
}),
customShareButton('telegram', {
icon: faTelegramPlane
}),
customShareButton('copy', {
icon: faLink
}),
customShareButton('check', {
icon: faCheck
}),
)
Sorry maybe I miss something. I couldn't find any info taht can help in the wiki.
UPD: I tried this approach, but also doesn't work: I replaced
export class AppModule {
// constructor(iconLibrary: FaIconLibrary) {
// iconLibrary.addIcons(...shareIcons);
// }
}
with
const iconLibrary = new FaIconLibrary();
iconLibrary.addIcons(...shareIcons);
@NgModule({
...
providers: [
provideShareButtonsOptions(
iconsLoaderFactory(iconLibrary),
),
...
],
...
UPD: when I use source-map-explorer
tool, it show correct size, maybe the problem is how I use webpack-bundle-analyzer
:
if I remove checkbox Show content of concatenated modules
in analyzer UI:
🤔
Reproduction
Is it correct that if I import custom icons, the size of the Fortawesome bundle should be reduced?
Steps to reproduce: Do some customisation according to this: https://github.com/MurhafSousli/ngx-sharebuttons/wiki/Icons-Guide-(legacy)#custom-icons
Expected Behavior
Reducing the size of the @fortawesome bundle
Actual Behavior
The size of the @fortawesome bundle is the same big:
Environment
packages.json
app.module.ts
share-buttons.component.html