尝试使用 webpack 加载 font-awesome 给了我这个错误:
ERROR in ./~/font-awesome/fonts/fontawesome-webfont.eot?v=4.6.3
Module parse failed: ...\node_modules\font-awesome\fonts\fontawesome-webfont.eot?v=4.6.3 Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type.
我正在尝试在这样的 React 组件中导入 font-awesome:
import "font-awesome/scss/font-awesome.scss";
这是我的 webpack.config.js 的样子。我想将 font-awesome 和相关资产与其他所有内容分开加载,即因为我已经用 babel 加载了 SVG,但不想用 font-awesome 加载。
{
test: /\.scss/,
loader: ExtractPlugin.extract("style", "css!sass")
},
{
test: /\.svg$/,
loader: "babel!svg-react",
exclude: /node_modules/
},
{
test: /\.ttf$/,
loader: "file-loader?mimetype=application/octet-stream&name=[name].[ext]",
exclude: /node_modules/
},
{
test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
loader: "url?limit=10000&mimetype=application/font-woff&name=[name].[ext]",
exclude: /node_modules/
},
{
test: /\.(otf|eot|png|svg|ttf|woff|woff2)(\?[\s\S]+)?$/,
loader: "url?limit=10000",
include: "node_modules/font-awesome/fonts"
}
我也试过像这样做正则表达式,但没有用:
{ test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url?limit=10000" }