简体   繁体   中英

React + Webpack SVG Icons Render Issues

I'm trying to render custom SVG icons that have been designed and exported for web. These are stored locally within an assets folder.

Using this package "svg-inline-loader"

Here is how I'm using the icon:

import MainLogo from '../../../assets/svg/logos/mainlogo.svg';

<img src={MainLogo} alt="" />

Here is the snippet I have from my webpack config

//SVG Icon Loader
      {
        test: /\.svg$/,
        loader: 'svg-inline-loader'
      },

The render output I get the following:

在此处输入图片说明

The SVG icons do not render however, that path does not look right.

Is there a better way to do this or what am I doing wrong here?

您可以使用Webpack服务器通过使用Copy WebPack Plugin将资源复制到公用文件夹来提供资产

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM