In my Next.js (9.4.4) / Tailwind.css (1.4.6) project, I'm using a custom font called SpaceGrotesk. To make it work, I put my fonts my public/fonts/spaceGrotesk
, and then, I configured my files as follows:
// next.config.js
module.exports = {
cssModules: true,
webpack: (config, options) => {
config.node = {
fs: "empty",
};
config.module.rules.push({
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
use: [
options.defaultLoaders.babel,
{
loader: "url-loader?limit=100000",
},
{
loader: "file-loader",
},
],
});
return config;
},
};
/** tailwind.css */
@tailwind base;
@tailwind components;
@tailwind utilities;
@font-face {
font-family: SpaceGrotesk;
font-weight: 400;
font-display: auto;
src: url(../public/fonts/spaceGrotesk/SpaceGrotesk-Regular.woff) format("woff");
}
// tailwind.config.js
module.exports = {
purge: {
mode: "all",
content: [
"./components/**/*.js",
"./Layout/**/*.js",
"./pages/**/*.js"
],
},
important: true,
theme: {
extend: {
fontFamily: {
paragraph: ["Crimson Text, serif"],
spaceGrotesk: ["SpaceGrotesk, sans-serif"],
},
},
},
};
I used to have a lot of trouble with import errors displayed on the console, but fixed them all. Now, however, I still don't get the right fonts. The console shows no warning, the inspector seems to say that the font is loaded correctly, but the back-up font (sans-serif) is still used instead of SpaceGrotesk.
What did I do wrong to import my font?