Webpack没有加载字体文件

时间:2016-02-28 20:00:43

标签: webpack urlloader

我对所有这些都比较新,并且一直在努力让我的字体被包含在我的style.css中。

起初它没有加载文件,因为路径不正确(显然它正在寻找从root而不是在fonts目录本身内的相对路径)。

似乎找不到文件,但告诉我我使用的是错误的加载程序。 见下文:

module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015', 'stage-0'],
          plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy'],
        }
      },
      {
        test: /\.scss?$/,
        loader: ExtractTextPlugin.extract('css!sass')
      },
      {
        test: /\.(png|woff|woff2|eot|ttf|svg)$/,
        loader: 'url-loader?limit=100000'
      }
    ]
  },

我得到的错误如下: enter image description here

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

您确定它是url-loader但不是file-loader

因为url-loader使用dataUrls而file-loader会发出文件。

让我们尝试以下内容,看看它是否有效〜

{ test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader?limit=10000&minetype=application/font-woff" }, { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" }