M
M
Michael2021-08-03 16:29:56
Fonts
Michael, 2021-08-03 16:29:56

Strange work with fonts?

Approximate project structure (regarding fonts):
dist
--fonts
----Roboto.ttf
src
--fonts
---Roboto
----Roboto.ttf

Fonts are connected only if I set an absolute path to them. And the path is to src/fonts/and not dist/fonts.
At the same time, the fonts folder is not created in dist during assembly.
Will there be problems in the future with such paths?

The second option: (didn't work, I don't know why)
In webpack.config.js I registered publicPath in modules for fonts, as some people advised.

{
                test: /\.(?:|woff(2)?|eot|ttf|otf)$/,
                type: 'asset/inline',
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            name: `./fonts/${filename('[ext]')}`,
                            publicPath: '../',
                        },
                    }
                ],
            },


The fonts are collected in dist/fonts, but when I try to use them in css, nothing happens. In the console it gives: Failed to decode downloaded font and OTS parsing error.
With OTS parsing, everyone advises to fight with the absolute path to the file.

How can I include fonts (with relative paths) so that when building in dist, the fonts folder is generated and there are no parsing errors?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question