无法将图像添加到我的反应项目

时间:2017-05-22 19:31:10

标签: javascript reactjs webpack

我想要一个像这样的图像:

const img = require('Flag');

它刚刚失败。

这是我的webpack.config.js:

module.exports = {
  entry: './app/app.jsx',
  output: {
    path: __dirname,
    filename: './public/bundle.js'
  },
  resolve: {
    root: __dirname,
    alias: {
      Game: 'app/components/Game.jsx',
      Board: 'app/components/Board.jsx',
      Row: 'app/components/Row.jsx',
      Cell: 'app/components/Cell.jsx',
      Flag: 'app/components/flag.png',
    },
    extensions: ['', '.js', '.jsx', '.png']
  },
  module: {
    loaders: [
      {
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015', 'stage-0']
        },
        test: /\.jsx?$/,
        exclude: /(node_modules|bower_components)/
      },
      {
        test: /\.(png|jpg)$/,
        loader: 'url?limit=25000'
      }
    ]
  },
};

0 个答案:

没有答案