reactjs - 使用 ReactJS 添加静态图像
问题描述
我在 StackOverflow 上读了很多东西,但在我的情况下它仍然不起作用。也许你能帮我解决这个问题吗?
在我的包裹中:
"file-loader": "^1.1.11",
"url-loader": "^1.1.1",
我的网络包:
module.exports = {
entry: ['./src/index.js'],
output: {
path: __dirname,
publicPath: '/',
filename: 'bundle.js'
},
module: {
loaders: [
{
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['react', 'es2015', 'stage-1']
}
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
}
]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
devServer: {
historyApiFallback: true,
contentBase: './',
watchOptions: {
aggregateTimeout: 300,
poll: 1000
}
},
};
我的代码:
import React, { Component } from 'react';
import ImgExplore from './icon-explore.png';
export default class Landing extends Component {
render() {
return(
<div>
<img src={ImgExplore} className="img-fluid" />
</div>
);
}
}
我收到这条消息
./src/components/icon-explore.png 中的错误模块构建失败:SyntaxError: Unexpected character '�' (1:0)
1 | �PNG | ^ 2 | 3 | 4 | IHDR��W�gAMA�a�IDATx�] �Tյ=����U
解决方案
推荐阅读
- python - How to use T=TypeVar('T', bound=...) with Type[T] correctly?
- python - 如何使用多个输入变量 LSTM 产生 1 个输出
- c++ - Problem Modifying Eigen Members of a C++ Structure
- php - 如何使用 brozot laravel 获取注册密钥或 fcm 令牌
- macos - (方案)复制粘贴代码时的未绑定变量
- visual-studio - f# xamarin 部署时空白 android 项目错误:无法解析参考:FSharp.Core
- git - 您可以向一组无法访问 repo / 添加到 jenkins 构建的用户打开 Jenkins 作业吗
- neo4j - 如何使用 CSV 中定义的关系将大型数据集导入 Neo4j
- python - str.contains pandas 返回 'str' 对象没有属性 'contains' 新使用 pandas
- javascript - 如何在不同子域之间共享本地存储?