Tree Shaking - automatically detecting usage
See original GitHub issueLooking at the recommended usage
src/main.js
import Vue from 'vue'
import App from './App'
import { library } from '@fortawesome/fontawesome-svg-core'
import { faUserSecret } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
library.add(faUserSecret)
Vue.component('font-awesome-icon', FontAwesomeIcon)
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
el: '#app',
components: { App },
template: '<App/>'
})
src/App.vue
<template>
<div id="app">
<font-awesome-icon icon="user-secret" />
</div>
</template>
<script>
export default {
name: 'App'
}
</script>
And then the tree shaking docs:
import { library } from '@fortawesome/fontawesome-svg-core'
import { faCoffee } from '@fortawesome/free-solid-svg-icons/faCoffee'
import { faSpinner } from '@fortawesome/pro-light-svg-icons/faSpinner'
library.add(faCoffee, faSpinner)
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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:10
- Comments:14 (2 by maintainers)
Top Results From Across the Web
Tree Shaking
Clarifying tree shaking and sideEffects ... The sideEffects and usedExports (more known as tree shaking) optimizations are two different things. sideEffects is ...
Read more >Tree shaking - MDN Web Docs Glossary
Tree shaking is a term commonly used within a JavaScript context to describe the removal of dead code.
Read more >Tree-shaking in real world: what could go wrong?
Tree-shaking is the process of detecting and marking dead code in your bundle based on ES modules' usage of import and export statements....
Read more >Tree Shaking - How to Clean up Your JavaScript
Tree shaking is a strategy web developers use to create leaner JavaScript bundles by getting rid of unused code. This guide will explain...
Read more >Learn about tree shaking in Webpack 5
Tree shaking is a technique used by webpack to optimize the builds for production and reducing the build size by shaking off the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay, as promised, here’s my repository https://github.com/GTANAdam/vue-fontawesome-autogen
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.