이미지:이 필요할 수 있는 적절한 로더는 이를 처리하기 위한 파일 유형

수't 그림에 무엇이 적절한 로더 이미지에 ReactJS 웹팩,

수요? 제가 이 오류가 발생할 수 있습니다.

Module parse failed: /Users/imac/Desktop/fakeeh/imgs/logo.png Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type.

여기에는 웹팩 config:

const path = require('path');

module.exports = {
  // the entry file for the bundle
  entry: path.join(__dirname, '/client/src/app.jsx'),

  // the bundle file we will get in the result
  output: {
    path: path.join(__dirname, '/client/dist/js'),
    filename: 'app.js',
  },

  module: {

    // apply loaders to files that meet given conditions
    loaders: [{
      test: /\.jsx?$/,
      include: path.join(__dirname, '/client/src'),
      loader: 'babel-loader',
      query: {
        presets: ["react", "es2015", "stage-1"]
      }
    }],
  },

  // start Webpack in a watch mode, so Webpack will rebuild the bundle on changes
  watch: true
};

많은 감사!!

해결책

또한 발생 이 문제는 너무 나는've 해결 방법을 발견.

첫째,당신을 설치해야 할 두 가지 로더(파일 로더,url-loader). 예: $npm--파일 저장 장 url 로더

하려는 경우 지원 css. 이 설치되어 있는지 확인 스타일에 있습니다. 예를 들어, $npm--저장식 로더 css 로더

다음으로,당신 업데이트 웹팩 config,친절하게 확인하는 아래 나의 샘플을 구성이 있습니다. 도움이 되기를 바랍니다.

  module: {
    loaders: [{
      test: /.jsx?$/,
      loader: 'babel-loader',
      exclude: /node_modules/
    }, {
      test: /\.css$/,
      loader: "style-loader!css-loader"
    }, {
      test: /\.(jpe?g|png|gif|woff|woff2|eot|ttf|svg)(\?[a-z0-9=.]+)?$/,
      loader: 'url-loader?limit=100000' }]
  },
해설 (1)

당신이 사용할 수 있는파일 로더. 당신은 그것을 설치할 필요가 처음 사용하 npm 한 후 편집하는 웹팩 config 다음과 같이

module: {

    // apply loaders to files that meet given conditions
    loaders: [{
      test: /\.jsx?$/,
      include: path.join(__dirname, '/client/src'),
      loader: 'babel-loader',
      query: {
        presets: ["react", "es2015", "stage-1"]
      }
    },
    {
      test: /\.(gif|svg|jpg|png)$/,
      loader: "file-loader",
    }],
  },
해설 (1)

된 웹팩 3 사용할 수 있습니다,url 로더다음과 같다.

Installurl 로더`:

npm install --save url-loader

그런 다음에서 당신의 웹팩 config:

module.exports = {
  module: {
    rules: [
      {
        test: /\.(png|jpg|gif)$/i,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 8192
            }
          }
        ]
      }
    ]
  }
}

마지막으로,코드:

해설 (1)

때로는 이 솔루션은 간단하고 바로 앞에 있습니다.

나는 즉시 시작하는 google 이 문제를 해결합니다. 하지만 내가 누락되었 jpg extention 테스트에서.

그렇게 나의 테스트:

테스트:/.(png|woff(2)?|eot|ttf|svg|gif|jpe?g)(\?[a-z0-9=\.]+)?$/

해설 (0)