The package has been extended from grunt-webfont and adapted to Magento 2 with the LESS preprocessor:
https://www.npmjs.com/package/grunt-webfont
ttfautohint is optional, but your generated font will not be properly hinted if it’s not installed. And make sure you don’t use ttfautohint 0.97 because that version won’t work.ttf2woff2.js:3 Invalid asm.js: Invalid member of stdlib
fontforge isn’t required for the node engine.https://github.com/nvm-sh/nvm/blob/master/README.md
brew unlink node
brew install node@12
brew link --overwrite --dry-run node@12
echo 'export PATH="/usr/local/opt/node@12/bin:$PATH"' >> ~/.zshrc
npm install grunt-m2webfont --save-dev
// or
yarn add grunt-m2webfont
brew install ttfautohint fontforge --with-python
sudo apt-get install fontforge ttfautohint
Install ttfautohint (optional).
Then install fontforge.
C:Program Files (x86)FontForgeBuildsbin to your PATH environment variable.Add all svg icons to the folder web/images/icons/font of a created theme.
Example:
app/design/frontend/{vendor}/{theme}/web/images/icons/font/*.svg
The module grunt-m2webfont will run for all themes which added to
dev/tools/grunt/configs/themes.js
or
dev/tools/grunt/configs/local-themes.js
if the file local-themes.js was added to a content of the file grunt-config.json in the root folder of a project.
Just run the command in a terminal:
grunt m2webfont
After importing and building styles you can use styles' mixins or html classes to add an icon.
Replace the fragment {name} to the name of an icon.
Example: @od-icon-arrow-down
The mixin .od-icon(@od-icon-{name}) will add properties such as: content and font-family
.class::before {
.od-icon(@od-icon-{name});
}
<i class="od-icon od-icon-{name}"></i>
The default engine to build a font is node in the Grunt’s config file to save minimum dependecies. But generated icons might be broken. To fix this issue you need to change the engine from node to fontforge in the config.
Just to comment the row in the file dev/tools/grunt/configs/m2webfont.js:
const options = {
...
// engine: 'node',
}
If you don’t set the engine to options then it will has a default value engine: 'fontforge'.
But to use FontForge you need install the engine to your OS.
See instructions above (Installation).
Just rebuild icons after installation.
Downgrade your Node version to 12.
See instructions above (Important).