Answer the question
In order to leave comments, you need to log in
Why does Webpack Encore only load the filename and not its content (require().default)?
The JS file has something like this:
const icon = require('path-to.svg').default;
div.innerHTML = icon;
<div><svg>...</svg></div>
<div>path-to.svg</div>
Answer the question
In order to leave comments, you need to log in
He asked himself - he answered.
You just need to install via npm/yarn raw-loader (if not already installed) and add to the path of the require file:
const icon = require('!raw-loader!path-to.svg').default;
If you use some special loader in Webpack, then why do you expect Webpack Encore to somehow magically use it too?
A simple check of the list of dependencies will show you what raw-loader
is not included in the list of dependencies, which means from the point of view of Webpack Encore, as well as from the point of view of Webpack (where it is only in dev.dependency) it is a custom loader, which clearly should have led you to corresponding section of the documentation .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question