Seems like it's a quite common problem but I couldn't find any solutions yet. I'm creating a project using webpack 4.41.2 where I need to use local fonts. Fonts are uploaded via @font-face. Here they are:
@font-face {
font-family: 'Roboto Slab', serif;
font-style: normal;
font-weight: 400;
src:
url('./fonts/robotoslab-regular-webfont.woff') format('woff'),
url('./fonts/RobotoSlab-Regular.ttf') format('truetype');
}
and a few more like the first one. Here is the structure:
I can't publish pics yet, but here's a link to screenshot
so everything should be all right.
My config:
{
test: /\.(ttf|eot|woff|woff2)$/,
use: {
loader: "file-loader",
options: {
name: "fonts/[name].[ext]",
publicPath: "",
},
},
},
In dist folder everything is like this:
I can't publish pics yet, but here's a link to screenshot
But even before I've made folders here, @font-face didn't work.
The strange part:
- dev tools don't show any errors;
- @import from the font.css works perfectly (I just really need to use local fonts for the project);
- fonts folder doesn't show up in dev tools sources.
There are no errors in build/dev too.
Earlier I had this problem with loading css background-image to webpack and I've solved it with adding publicPath: '../'
to MiniCssExtractPlugin.loader options. It doesn't work with fonts apparently.