Webpack can't load fonts (ttf)

前端 未结 4 1653
心在旅途
心在旅途 2021-02-20 05:56

Currently I have 3 fonts that I want to add to my React project:a, a light, a bold.
My file structure:

/src
├── /fonts/
│   ├── /A.ttf
│   ├── /A-         


        
4条回答
  •  渐次进展
    2021-02-20 06:36

    Using 'ttf-loader' from npm worked perfectly for me.

    https://www.npmjs.com/package/ttf-loader

    module: {
      rules: [
        {
          test: /\.ttf$/,
          use: [
            {
              loader: 'ttf-loader',
              options: {
                name: './font/[hash].[ext]',
              },
            },
          ]
        }
      ]
    }
    

提交回复
热议问题