问题
I encountered this error
ERROR in ./src/style/MyFont.ttf Module parse failed: /xxx/MyFont.ttf Unexpected character '' (1:0) You may need an appropriate loader to handle this file type. (Source code omitted for this binary file)` when I import my custom font in my less file like this:
@font-face {
font-family: "MyFont";
src: url("./MyFont.ttf") format("truetype");
}
my webpack config is as follow:
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: babelQuery
},{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.less$/i,
use: ExtractTextPlugin.extract([ 'css-loader', 'less-loader' ])
},
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/octet-stream" },
]
Anyone knows how to solve it?
回答1:
Add this to your rules
array.
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'file-loader?name=assets/[name].[hash].[ext]'
}
and you should install the file-loader
using npm install
.
Hope this will help you.
来源:https://stackoverflow.com/questions/47303407/why-does-module-parse-failed-xxx-myfont-ttf-unexpected-character