webpack-contrib / file-loader

File Loader
MIT License
1.86k stars 257 forks source link

SVG icon shows up as text in the loaded application index.html #343

Closed tusharosu closed 5 years ago

tusharosu commented 5 years ago

Expected Behavior

The svg icon should show up as an image in the loaded application's html page

Actual Behavior

The svg icon shows up as the following text in the loaded application's html page module.exports = __webpack_public_path__ + "images/97f09d2d69ed0771769efa0d68f58476.svg";

Code

Here is the webpack.config.js loader configuration (followed the documentation for asset management): loader configuration for webpack.config.js

Here is the code that loads the svg image (The checkbox shows up fine when the applciation is loaded using the source code instead of from the minified bundle):

define([
 .....
  'tristate-checkbox/TristateCheckbox'
], (declare, TristateCheckbox, ...) => {
  ....
      let checkbox = TristateCheckbox({ id: 0, checked: true, name: 'test' });
      let tristateDiv = document.getElementById('tristate');
      tristateDiv.appendChild(checkbox);
    }
  });
});

The TristateCheckbox.js does the following to load the image:


define([..., 'dojo/text!./images/TristateCheckboxSVG.svg'], function (..., svgDoc) {
  'use strict';
  var div = document.createElement('div');
  div.innerHTML = svgDoc;
  var svg = div.firstChild.cloneNode(true);
...

How Do We Reproduce?

Using the configuration provided above.

ipatch commented 5 years ago

having the exact same behavior as well.

using

also while skimming through the README i didn't see any examples that contained SVG as a filetype that file-loader can handle, so not exactly sure that this webpack loader can even handle SVG. 🤷‍♂️

Update

You might want to take a look at this

https://webpack.js.org/loaders/svg-inline-loader/

seems to get the job done for me, as I was able to add a SVG to the DOM.

cheers 🍩

tusharosu commented 5 years ago

Thanks for the advice Chris! Got it working with the svg-inline-loader!