0
React 응용 프로그램에서 이미지 번들을 사용하기 시작했으나 브라우저에 표시되지 않습니다 (<img/>
태그가 있지만 이미지가 없음). "webpack"을 실행하면 이미지가 공용 폴더에 해시 이름으로 표시되고 "webpack-dev-server"를 실행하면 이미지가 번들로 표시되지만 브라우저에는 아무것도 표시되지 않습니다. 이 내 웹팩 구성 파일입니다webpack을 통한 처리 후 이미지가 표시되지 않음
module.exports = (env) => {
const isProduction = env === 'production';
const CSSExtract = new ExtractTextPlugin('styles.css');
return {
entry: ['babel-polyfill', './src/app.js'],
output: {
path: path.resolve(__dirname, './public/scripts'),
filename: 'bundle.js'
},
module: {
rules: [{
loader: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/
},
{
test: /\.(png|jp(e*)g|svg)$/,
use: [{
loader: 'url-loader',
options: {
limit: 8000, // Convert images < 8kb to base64 strings
name: 'images/[hash]-[name].[ext]'
}
}]
},
{
test: /\.s?css$/,
use: CSSExtract.extract({
use : [
{
loader : 'css-loader',
options : {
sourceMap : true // source map for css in development
}
},
{
loader : 'sass-loader',
options : {
sourceMap : true
}
},
{
loader: "jshint-loader"
}
]
})
},
]
},
plugins : [
CSSExtract,
],
devtool: isProduction ? 'source-map' : 'cheap-eval-source-map', // source map for locating a bug in source files, not in the bundle
devServer: {
contentBase: path.join(__dirname, "public"),
publicPath: "/scripts/",
historyApiFallback: true // this line is for client-side routing
},
}
}
이 내가 내 응용 프로그램에 이미지를 추가하는 방법입니다 :
import img1 from '../../assets/img/ticket.jpg';
이 내가 render()
방법에서 사용하는 방법입니다.
<img src={img1}/>
나는이 브라우저 DevTools로에서 볼 수 있지만 이미지 자체는 표시되지 않습니다 :
<img src="images/9011429377e91d003e5b64251ac3b9a8-ticket.jpg">
어떻게 그것을 수정하고 이미지를 표시 할 수 있습니까?
@JasonAllshorm, 감사 :
그리고 내 웹팩에서 나는이있다! 불행히도 그게 내 문제를 해결하지 못했습니다. 당신이 제안한 변경 후에도 여전히 브라우저에 이미지가 나타나지 않습니다. – turisap