我在react-babel-webpack中使用了一个图像文件。但它显示错误
ERROR in ./public/assets/scissors.png
Module parse failed: /home/rohit/Desktop/game/public/assets/scissors.png
Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected character '�' (1:0)
tool.component.js
import React from 'react';
import Paper from '../../public/assets/paper.png';
import Rock from '../../public/assets/rock.png';
class Tools extends React.Component {
render(){
return (
<div>
<img src={Paper} name="Paper" onClick={this.select.bind(this)} className="game-icon" alt="logo" />
<img src={Rock} name="Rock" onClick={this.select.bind(this)} className="game-icon" alt="logo" />
</div>
);
}
};
export default Tools;
webpack.config.dev.js
import path from 'path'
import webpack from 'webpack';
export default {
devtool: 'cheap-module-eval-source-map',
entry: [
'webpack-hot-middleware/client',
path.join(__dirname, '/client/index.js')
],
output: {
path: '/',
publicPath: '/'
},
plugins: [
new webpack.NoErrorsPlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin()
],
module: {
loaders: [
{
test: /\.js$/,
include: path.join(__dirname, 'client'),
loaders: [ 'react-hot', 'babel' ]
},
{ test: /\.css$/, loader: "style-loader!css-loader" },
{ test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [ 'file?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
]}
]
},
resolve: {
extentions: [ '', '.js', '.css' ]
}
}
答案 0 :(得分:0)
添加&#39; .png&#39;进入扩展数组:
2017-03-10
编辑:已解决的拼写错误