Search code examples
javascriptwebpackbundlebundler

Wrong path to font in MiniCssExtractPlugin


I have a 404 error because the font path is wrong. Now is dist/font , but page try find it at dist/style/font .

This is my config jsfiddle.net/sicely/z8g5sr9e

I am import fonts in this way

@font-face {
    font-family: 'Roboto-Bold';
    src: url(../assets/fonts/Roboto-Black.ttf) format("truetype")
}

If I put all my bundle in the root, all work fine


Solution

  •         {
                test: /\.(ttf|woff)$/,
                use: {
                    loader: 'file-loader',
                    options: {
                        name: 'fonts/[name].[hash:6].[ext]',
                        publicPath: '../',
                    },
                },
            }
    

    Problem solved if I add a publicPath to file-loader options