-
Notifications
You must be signed in to change notification settings - Fork 133
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 vs import #293
Comments
What you are doing in the 2nd code is not tree shaking, you are importing all the icons |
Thanks @christhofer, I suspected so. Then though I don't understand the usefulness of the library. From the docs it seems to me it's suggested the library allows you to reduce the final bundle size
Do you have some more insight on what the library does and how it helps to keep the bundle small? |
By doing this, only 4 icons are imported, so the final bundle only contains 4 icons you need instead of all font awesome icons. Regarding library.add(), I'm also not really sure how it works. |
I would suggest to use explicit usage, this way you are 100% sure you only bundle what you use <template>
<FontAwesomeIcon :icon="$options.icons.faEye" />
</template>
<script>
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { faEye } from '@fortawesome/pro-regular-svg-icons/faEye'
export default {
components: { FontAwesomeIcon },
icons: { faEye },
// ...
}
</script> ps: we killed 4mb of bundle size just by using explicit icon imports |
I get |
@iamandrewluca I did your approach and a huge improvement on size. Why is there no documentation on this vs every example they provide has them using this approach: import { faEye } from '@fortawesome/pro-regular-svg-icons/' vs import { faEye } from '@fortawesome/pro-regular-svg-icons/faEye' The first approach drops in that huge index file, etc. |
@brianrwells It's because most modern tools (webpack, rollup, esbuild) can handle tree-shaking |
@robmadole So its a pretty recent Vue project, we followed FontAwesome's examples for install ... in fact I just made sure I am using the last version of Webpack. What if any misconfig issue would cause the tree shaking to not occur? |
@brianrwells did you run a production build? |
yarn run stats |
Can you check the actual file size on disk too? We've seen problems with analyzer reporting larger than actual sizes. |
@robmadole with our fonts setup like this `import { library, dom } from "@fortawesome/fontawesome-svg-core" import { library.add( gives us this |
So I'm assuming it landed in |
@robmadole Its not tree shaking, in chunk map file, faBowlingPins is there which it should not be |
doing it this way `import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome" //free-solid-svg-icons //free-brands-svg-icons //free-brands-svg-icons //pro-duotone-svg-icons //pro-solid-svg-icons give us this: |
Hello, in the many examples I saw online on how to import the icons to reduce the dimensions of the build I found a lot of repetition:
Would the following work the same, with the tree-shake doing its thing?
The text was updated successfully, but these errors were encountered: