0

我试图让我的图像出现在我的反应代码的构建版本中。

```import reportIcon from "../../../../../src/img/reportmanager.svg"; 
<img src={reportIcon } className="img-icons-list" />```

当我处于构建版本时,此代码有效。我的报告管理器图标出现了,但是当我导航到 www.mywebsite.com/reports/user 时——图标消失了 import reportIcon from "/src/img/reportmanager.svg";

也不起作用。这是我的 webpack.config.js 文件

```const HtmlWebPackPlugin = require("html-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
var path = require('path');
module.exports = {
entry: './src/index.js',
output: {
    path: path.resolve(__dirname + '/public'),
    filename: 'bundle.js'
},
module: {
    rules: [
        {
            test: /\.(js|jsx)$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
            options: {
                presets: ['@babel/preset-env',
                    '@babel/react', {
                        'plugins': ['@babel/plugin-proposal-class-properties']
                    }]
            },
        },
        {
            test: /\.css$/,
            use: ExtractTextPlugin.extract({
                fallback: "style-loader",
                use: "css-loader"
            })
        },
        {
            test: /\.(eot|ttf|woff|woff2)$/,
            loader: 'file-loader?name=./font/[name]_[hash:7].[ext]'
        },
        {
            test: /\.(jpg|png|svg)$/,
            loader: 'file-loader?name=./img/[name]_[hash:7].[ext]'
        }

    ]
},
devServer: {
    historyApiFallback: {
        index: "/",
    }
},
plugins: [
    new ExtractTextPlugin("css/style.css"),
    new HtmlWebPackPlugin({
        template: "./src/index.html",
        filename: "./index.html"
    }),
    function () {
        this.plugin("done", function (stats) {
            if (stats.compilation.errors && stats.compilation.errors.length && process.argv.indexOf('--watch') == -1) {
                console.log(stats.compilation.errors);
                process.exit(1); // or throw new Error('webpack build failed.');
            }
            // ...
        });
    }
]
};
4

1 回答 1

1

我需要把

<base href="/">

在我的反应项目的 index.html 中。

于 2019-03-25T22:56:49.503 回答