Open riha opened 4 years ago
Hi!
Thanks for being part of the Font Awesome Community.
Sorry, cannot help.
Leaving this open for feedback from the community
I'm having the exact same issue. None of the solutions I've found online have helped, like using import {faSignInAlt} from '@fortawesome/free-solid-svg-icons/faSignInAlt';
instead of import {faSignInAlt} from '@fortawesome/free-solid-svg-icons';
It looks like https://github.com/FortAwesome/Font-Awesome/blob/master/js-packages/%40fortawesome/free-regular-svg-icons/index.es.js#L766 is a map that holds on to references from every other icon. I'm not sure webpack@5 pretty sure can't optimize this out because the map could be side effectful. Adding "sideEffects": false
to the package.jsons might be enough though. https://webpack.js.org/configuration/optimization/#optimizationsideeffects
Hi, we already have sideEffects: false
in package.json
@tagliala I can't seem to find where a mapping would force webpack@5 to hold onto all of @fortawesome/free-solid-svg-icons
. I did see that @fortawesome/react-fontawesome
allows strings to be used for icons (which hints at a mapping). @fortawesome/fontawesome-svg-core/index.es.js's two used exports (icon
and parse
) don't ever reference an external map from what I can tell, so I don't think they'd be responsible.
The following code
import ReactDOM from 'react-dom'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faCoffee } from '@fortawesome/free-solid-svg-icons'
const element = <FontAwesomeIcon icon={faCoffee} />
ReactDOM.render(element, document.body)
with Webpack 5 stats set to
module.exports = {
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
},
},
],
},
stats: {
logging: 'verbose',
moduleTrace: true,
orphanModules: true,
usedExports: true,
},
}
Shows the chain of...
./node_modules/@fortawesome/react-fontawesome/index.es.js 10.8 KiB [orphan] [built]
[only some exports used: FontAwesomeIcon]
./node_modules/@fortawesome/fontawesome-svg-core/index.es.js 76.7 KiB [orphan] [built]
[only some exports used: icon, parse]
./node_modules/@fortawesome/free-solid-svg-icons/index.es.js 695 KiB [orphan] [built]
[only some exports used: faCoffee]
edit it looks like the stats output of webpack (695 KiB) for @fortawesome/free-solid-svg-icons is the parsed size of the library. Looking at the bundle output, there are no icons but the requested coffee icon in the bundle. I think this ticket can probably be closed.
@wegry thanks for the heads-up
edit it looks like the stats output of webpack (695 KiB) for @fortawesome/free-solid-svg-icons is the parsed size of the library. Looking at the bundle output, there are no icons but the requested coffee icon in the bundle. I think this ticket can probably be closed.
I remember some comments by Rob to check the actual size of the bundle in another issue related to tree-shanking: https://github.com/FortAwesome/Font-Awesome/issues/16005#issuecomment-610412303
I thought I was seeing the same issue, but it turned out to be a the wrong source maps option in webpack.
I thought I was seeing the same issue, but it turned out to be a the wrong source maps option in webpack.
Can you post the solution?
@AlonsoK28
It might have been specific to my app, but here's the change I made
Basically removing the source map from production
It might have been specific to my app, but here's the change I made
please provide your webpack
config file
I have a simple React, Typescript project with an import of one icon. I do however end up with the full index.es.js file in the bundle ...
Is it obvious for someone what I'm doing wrong here to get the Tree Shaking to work? 😯
component.tsx
webpack.config.js
package.json