Hi folks,
We are in the process of a Sage 9 to 10 upgrade. We use Fontsource fonts (self-hosted Google fonts), installed via NPM/Yarn but am struggling to get them to work.
Previously on Sage 9, they were included as follows:
- installed via NPM
- imported specific styles & weights in theme CSS file
@import "@fontsource/exo-2/300.css";
@import "@fontsource/exo-2/300-italic.css";
@import "@fontsource/exo-2/400.css";
// etc...
- Within each of these CSS files (inside
node_modules
) are a series of .woff imports, eg
@font-face {
font-family: 'Exo 2';
font-style: normal;
font-display: swap;
font-weight: 300;
src: url('./files/exo-2-cyrillic-ext-300-normal.woff2') format('woff2'), url('./files/exo-2-all-300-normal.woff') format('woff');
unicode-range: U+0460-052F,U+1C80-1C88,U+20B4,U+2DE0-2DFF,U+A640-A69F,U+FE2E-FE2F;
}
When I tried to compile, the path to the .woff
files couldn’t be resolved so I had to create an entry in my webpack.mix.js
file to copy the node_modules/@fontsource/exo-2/files/*.woff
files from node_modules
to the dist
directory, eg:
mix.copyDirectory('node_modules/@fontsource/exo-2/files', 'dist/styles/files');
- I also had to add
processCssUrls: false
as a Mix option for the URLs to resolve:
mix
.autoload({ jquery: ["$", "window.$", "window.jQuery", "jQuery", "jquery"] })
.options({ processCssUrls: false })
In Sage 10 with Bud 6.7.3, I’ve done the equivalent of steps 1-3 above. The following in bud.config.js
handles the file copy
await app.fs.copy("node_modules/@fontsource/exo-2/files", "public/css/frontend/files")
I’m seeing the .woff
files in public/css/{entryPointName}/files
But I’m getting
Can't resolve './files/exo-2-all-300-normal.woff' in './resources/styles/frontend'
ie it’s trying to get the font files from the theme’s resources
directory rather than public
.
I haven’t done anything equivalent to the Mix option of processCssUrls
and can’t find anything in the Bud docs. I was wondering if anyone knew how to do this? (or a better way, generally speaking, for including @fontsource fonts!)
Thanks in advance