Hello world!
I would like to share my (hacky) workaround for those having issues with trying to get the urls in font-face to work without errors in ParcelJS.
Steps
- Run
parcelin your terminal to make sure all yourHTMLfiles have been created inside the/distfolder that is generated when you run the command for the first time. - Kill the
parcelprocess. (Win and Mac:Ctrl+C) - Create a folder in the
/distfolder to store your fonts (Example:/fonts), and move your font files into it. - Create a
.cssfile with your@font-facecode in it. (I named itfont-faces.css) (Sample code below) - Import the
font-faces.cssinto each of yourHTMLfiles via the<link>tag. - Run
parcel <your-html-file.html>again and refresh your web browser. If done right, you should see your fonts loaded properly.
Sample code:
@font-face{
font-family: "Montserrat";
font-weight: 100;
font-style: normal;
src: url("./fonts/montserrat/Montserrat-Thin.ttf"), format("truetype");
}
Some Notes/Tips
- Version
1.10.3of ParcelJS was used at the point of writing this workaround. - You'll have to resort to plain ol'
cssfor importing fonts via@font-face. - Do not include the
<link>to thefont-faces.cssin the originalHTMLfiles. As this may result in the same errors as trying to bundle@font-faceinSASS. Include it in theHTMLfiles in the/distfolder.
Hope this helps anyone facing these issues.
Others
In case this helps anyone, I'm also sharing the gist I wrote to help generate the @font-face code quickly. To use it, simply run node gen-fontface in your terminal and copy the output into your CSS file.
Updates
- Added another tip
- Added Others section
Top comments (0)