How I Can Make Svg Icons Appear After Spring-Boot: Run

I'm trying to place som icons from sprite.svg file

That's the fragment of my component in react, where I want to place image. and webpack config. I placed sprite.svg in href, but it doesn't works. Am I need to change my webpack.config, or install some modules?

<div className="product__actions">
    <div className="rating">
        <svg width="20px" height="20px" xmlns="">
            <use xlinkHref="#icon-rating"/>
        </svg>
        <span className="rating__result">{this.props.product.money_value}</span>
    </div>
 </div>

that's my webpack config

const path = require('path');

module.exports = {
    entry: {
        home: './src/main/js/home/home.js',
        products: './src/main/js/products/products.js',
        ....
        _catalog: './src/main/resources/styles/_catalog.scss',
        ....

    },
    cache: true,
    mode: 'development',
    output: {
        path: __dirname,
        filename: './src/main/resources/static/built/[name].bundle.js'
    },
    module: {
        rules: [
            ...
            {
                test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
                include: [path.join(__dirname, "src/assets")],
                loader: "file-loader?name=assets/[name].[ext]"
            }
            ...
        ]
    },
    plugins: [
        new MiniCssExtractPlugin({
            filename: './src/main/resources/static/css/[name].css'
        }),
        new MergeIntoSingleFilePlugin({
            files: {
                "./src/main/resources/static/styles/styles.css": [
                    './src/main/resources/static/css/_catalog.css',
                    .....
                ]
            }
        })
    ]
};

How I can solve this problem, pls help!

8

1 Answer

I should use correct full path to sprite.svg file

<use href="./resources/static/sprite.svg#icon-rating"/>

It works for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest