gpt4 book ai didi

reactjs - 模块解析失败 : Unexpected character '�' (1:0) You may need an appropriate loader to handle this file type

转载 作者:行者123 更新时间:2023-12-04 12:25:36 25 4
gpt4 key购买 nike

我正在为我的 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 中运行的 styleguidist 服务器中显示条形码图像.
我的 styleguidist 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" />
```

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

Please click to see the Error console

最佳答案

您需要图像的 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
}
}
}
]
}
}
}

关于reactjs - 模块解析失败 : Unexpected character '�' (1:0) You may need an appropriate loader to handle this file type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55234804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com