-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce bundle size after the fontawesome icons changes (#707)
* Use our own AwesomeIcon component instead of FontAwesomeIcon, this reduces minified build by 66 kB * Remove @fortawesome/react-fontawesome dependency * Replace classNames dependency by clsx
- Loading branch information
1 parent
5d75aae
commit 5036eda
Showing
15 changed files
with
140 additions
and
99 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Use <AwesomeIcon icon={faEye} /> instead of <FontAwesomeIcon icon={faEye} /> from @fortawesome/react-fontawesome | ||
Using FontAwesomeIcon component adds 66 kB minified to the bundle. | ||
Our AwesomeIcon does the same but less than 2 kB minified. | ||
svg-inline--fa class has been added to lib.styl | ||
*/ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
function asIcon(icon) { | ||
const width = icon[0]; | ||
const height = icon[1]; | ||
const vectorData = icon[4]; | ||
let element; | ||
|
||
if (Array.isArray(vectorData)) { | ||
element = ( | ||
<g> | ||
{vectorData.map((pathData, index) => ( | ||
<path key={index} fill="currentColor" d={pathData} /> | ||
))} | ||
</g> | ||
); | ||
} else { | ||
element = <path fill="currentColor" d={vectorData} />; | ||
} | ||
|
||
return { | ||
width: width, | ||
height: height, | ||
icon: element | ||
}; | ||
} | ||
|
||
export class AwesomeIcon extends React.Component { | ||
static propTypes = { | ||
icon: PropTypes.object.isRequired | ||
}; | ||
|
||
render() { | ||
const { width, height, icon } = asIcon(this.props.icon.icon); | ||
return ( | ||
<svg | ||
role="img" | ||
className={`svg-inline--fa fa-${this.props.icon.iconName}`} | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox={`0 0 ${width} ${height}`} | ||
> | ||
{icon} | ||
</svg> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.