模块解析失败:意外字符'�'(1:0)您可能需要一个适当的加载器来处理此文件类型。

4
我正在为我的React应用程序使用Styleguidist,这是我的styleguid.config.js文件的代码:
module.exports = {
  webpackConfig: {
    module: {
      rules: [
        // Babel loader, will use your project’s .babelrc
        {
          test: /\.jsx?$/,
          exclude: /node_modules/,
          loader: 'babel-loader'
        },
        // Other loaders that are needed for your components
        {
          test: /\.css$/,
          loader: 'style-loader!css-loader?modules'
        }
      ]
    }
  }
}

现在我想在运行在http://localhost:6060的样式指南服务器中显示条形码图像。 我的样式指南readme.md代码
```jsx
var Macybarcode = require('../../../containers/assets/img/macy/barcode.png');
const barcode_img = Macybarcode;
const barcode_no = "33527111690008";

<BarcodeMacy1 imgString={barcode_img} lineString={barcode_no} paddingTop="20px" width="50%" height="40px" />   
```

但是每当我尝试显示图片时,我的服务器就会出现以下错误:

请单击查看错误控制台

2个回答

5

您需要使用url-loader来处理图片

用法:

npm install url-loader --save

module.exports = {
  webpackConfig: {
    module: {
      rules: [
        // Babel loader, will use your project’s .babelrc
        {
          test: /\.jsx?$/,
          exclude: /node_modules/,
          loader: 'babel-loader'
        },
        // Other loaders that are needed for your components
        {
          test: /\.css$/,
          loader: 'style-loader!css-loader?modules'
        },
        {
                test: /\.(jpg|png|svg)$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        limit: 25000
                    }
                }
            }
      ]
    }
  }
}


0
try this line inside    
 { test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接