I am currently working on bundling a theme package using Rollup.js. The theme contains some global styles, specifically @font-face. I am importing the fonts and planning to inject them using styled-components injectGlobal.
However, I am encountering an issue when trying to bundle the package as Rollup is encountering errors with the font files. I initially thought that Webpack and Rollup could be used interchangeably, but it seems that is not the case. What is the correct approach to solve this problem?
Error message in console:
{ SyntaxError: /Users/****/sites/vz-react/packages/Theme/fonts/NeueHaasGroteskDisplayBold.woff: Unexpected character '' (1:4)
> 1 | wOFF: 6OS/2lZ` VDMXwmtcmap@\(cvt `
| ^
2 |
fpgm
3 | cgasp
glyf
IrheadV66!vhheaV!$hmtxW;*+kernZ$;ĭloca'p\maxp+ [name+ y*/post4 prep57ڀڄxc`fb
4 | 9X@ax3800fbf/py9#N3(!RxeTgf`uƌ3f`H(ݠw=wO?\ddGNf2,dod%tžl2;
...
globalStyles.js:
import NeueHassGroteskDisplayBold from '../fonts/NeueHaasGroteskDisplayBold.woff';
import NeueHassGroteskDisplay from '../fonts/NeueHaasGroteskDisplay.woff';
import NeueHassGroteskText from '../fonts/NeueHaasGroteskText.woff';
import NeueHassGroteskTextBold from '../fonts/NeueHaasGroteskTextBold.woff';
const injectGlobalStyles = () => `
* {
box-sizing: border-box;
}
*:focus {
outline: #000 dotted 1px;
outline-offset: 1px;
}
body {
padding: 0;
margin: 0;
}
@font-face {
font-family: 'NHGDisplay';
src: url(${NeueHassGroteskDisplayBold}) format("woff");
font-weight: bold;
font-style: normal;
}
@font-face {
font-family: 'NHGDisplay';
src: url(${NeueHassGroteskDisplay}) format("woff");
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'NHGText';
src: url(${NeueHaasGroteskText}) format("woff");
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'NHGText';
src: url(${NeueHaasGroteskTextBold}) format("woff");
font-weight: bold;
font-style: normal;
}
`;
export default injectGlobalStyles;