-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Font Awesome 5.0/5.1, webpack and tree shaking not working correctly #11311
Comments
Treeshaking is just (available) for JS. Unused css can be removed with solutions like nanocss, uncss, purgecss and so on. |
SplitChunks, AggressiveSplitting and other plugins can be also used. Or try the minicss plugin to extract the styles to a css file. |
Which webpack and gulp version do you use? Is the filesize on the filesystem the same? |
The size of dist/assets/js/app.min.js on the filesystem is 824 KB, and webpack says this during the build process:
Here is a paste of my package.json file:
|
And which commits of the fontawesome packages are in the lockfile? Because this is clearly an issue with the fontawesome package and not us or webpack in general imho. Treeshaking is normally just for JS classes and methods. Treeshaking fonts for user facing solutions where they can enter text is not a good idea in general. So I think this is just an issue with fontawesome and their |
Here is a paste of the relevant portion of the lock file. Can you elaborate on what you mean by it not being a good idea? This is my first experience with tree shaking so I'm learning as I troubleshoot this.
|
Because it would remove unused icons which users might need in dynamically added content. |
Well, in general we use webpack-stream which uses webpack under the hood. There is a normal webpack config used in our templates. Is somewhere the whole repository with the problematic code so we can clone and test with it? Per se the issue is not foundation-sites but the usage of webpack. I would say we close this issue here as this is more an issue with fontawesome and webpack. |
I hear you on tree shaking with dynamically added content. In our case we're not going to run into that issue, but I can see where it could be a problem. Unfortunately there isn't anything public that I can show you to test out. I am able to import the icons without tree shaking, so I will close this out, but I would request that you guys keep an eye on this issue since fontawesome 5.x is now live and popular, and webpack looks to be the future direction of both yours, and their, project. |
It is not an issue with foundation sites imho ;-) |
Expected Behavior
When running
gulp build --production
with font awesome version 5.0/5.1 installed and properly imported in app.js, webpack should properly "tree shake" and include in the final build ONLY the fonts that are imported and NOT the entire library(ies).I know this is not foundation-sites specific, but after trying to troubleshoot at FortAwesome/Font-Awesome#13232 I'm asking here for your gulp / webpack / uglifyjs expertise since gulp is handling webpack and uglifyjs (from what I can understand) in this project.
Current Behavior
The whole font awesome style library is being included in the final app.js build regardless of the environment flag, ballooning my app.min.js file size to ~700 kbs.
Possible Solution
After reading webpack/webpack#2867 and mishoo/UglifyJS#1261 and FortAwesome/Font-Awesome#12429 (comment) I have tried upgrading the following packages to these versions:
I have also tried adding
"sideEffects": false,
to my project's package.json file andmode: "production"
to mywebpackConfig
variable inside ofgulpfile.babel.js
. Neither fix the issue.My builds are successful, but the file size is still ballooning:
Test Case and/or Steps to Reproduce (for bugs)
How to reproduce:
Font Awesome 5.1 (prerelease) is where they are focusing their tree shaking fix development efforts, so those steps are:
gulp build --production
Docs: https://fontawesome.com/preview/how-to-use/use-with-node-js
Context
I cannot migrate to Font Awesome 5.x until this is fixed.
Your Environment
Checklist (all required):
The text was updated successfully, but these errors were encountered: