您可能需要适当的加载程序来处理此文件类型上载映像文件

时间:2017-03-28 18:28:41

标签: reactjs webpack babeljs react-redux webpack-dev-server

我在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' ]
  }
}

1 个答案:

答案 0 :(得分:0)

添加&#39; .png&#39;进入扩展数组:

2017-03-10

编辑:已解决的拼写错误