Using require('...') with a variable vs. using a string in webpack
<p>I have a problem that doesn't make much sense to me. </p>

<p>I'm mapping an array of objects that have a "name" and a "href" property. </p>

<pre><code>let appleIcons = _.map(appleIcons, appleIcon =&gt; {
  appleIcon.href = require(appleIcon.href);
  return appleIcon;
}); 
</code></pre>

<p>Inside of the loop I want to require the image but it throws an error ".*$:11 Uncaught Error: Cannot find module".</p>

<p>When I print the value of appleIcon.href and i try to put it directly into the require('') it works.</p>

<pre><code>appleIcons = _.map(appleIcons, appleIcon =&gt; {
  appleIcon.href = require('./../../mobile-config/apple-icon-57x57.png');
  return appleIcon;
});
</code></pre>

<p>So can you explain me why the second example works and the first one throws an error? How do i put a variable inside of require('')?</p>

<p>Thanks!</p>