how to set up an inline svg with webpack

后端 未结 9 1914
感动是毒
感动是毒 2020-12-02 16:49

I am wondering how to set up an inline svg with webpack?

I am following the react-webpack-cookbook.

I have my webpack.config set up correc

9条回答
  •  不思量自难忘°
    2020-12-02 17:13

    Here is a simple non-react solution.

    1. Install Svg inline loader
    2. In webpack.config.js add { test: /\.svg$/, loader: 'svg-inline-loader' }
    3. In your js file import svg image and add it to a DOM element like so
      import Svg from './svg.svg';
    
      function component() {
        const element = document.createElement('div');
    
        element.innerHTML = Svg;
    
        return element;
      }
    
      document.body.appendChild(component());
    

提交回复
热议问题