我正在使用 Webpack 使用 React,但无法加载静态图像。加载程序似乎正确地将图像转换为 URL,但在呈现页面时它似乎不能作为 img src。图片的相对路径正确。这是我的代码如下:
webpack.config.dev.js:
module: {
loaders: [
{
test: /\.css$/,
exclude: /node_modules/,
loader: 'style-loader!css-loader?localIdentName=[name]__[local]__[hash:base64:5]&modules&importLoaders=1&sourceMap!postcss-loader',
}, {
test: /\.css$/,
include: /node_modules/,
loaders: ['style-loader', 'css-loader'],
}, {
test: /\.jsx*$/,
exclude: [/node_modules/, /.+\.config.js/],
loader: 'babel',
}, {
test: /\.(jpe?g|gif|png|svg)$/i,
loader: 'url-loader',
options: {
limit: 25000,
},
}, {
test: /\.json$/,
loader: 'json-loader',
}, {
test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' }
],
},
Run Code Online (Sandbox Code Playgroud)
反应代码
import React, { Component} from 'react';
import styles from './Album.css';
const logo = require('./img/MoP.png');
export class …Run Code Online (Sandbox Code Playgroud)