gpt4 book ai didi

reactjs - 图片: You may need an appropriate loader to handle this file type

转载 作者:行者123 更新时间:2023-12-03 13:02:51 25 4
gpt4 key购买 nike

我不知道在 ReactJS webpack 中加载图像的正确加载器是什么,

你可以帮我一下吗?我收到此错误:

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.

这是 webpack 配置:

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
};

非常感谢!!

最佳答案

我也遇到了这个问题,并且找到了解决方法。

首先,您需要安装两个加载器(file-loader、url-loader)。例如$ npm install --save file-loader url-loader

如果你想支持css。确保安装了样式加载器。例如。,$ npm install --save style-loader css-loader

接下来,您更新 webpack 配置,请检查下面我的示例配置。希望对您有所帮助。

  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' }]
},

关于reactjs - 图片: You may need an appropriate loader to handle this file type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45848055/

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