Read a file at resolved path in Webpack
<p>I have a node module and I want to make it compatible with webpack. I'm currently using the following pattern:</p>

<pre><code>const fs = require('fs');
const someTemplate = require.resolve('./templates/template.css');

fs.readFile(someTemplate, 'utf8', (err, templateStr) =&gt; {
  // Do something with`templateStr`
});
</code></pre>

<p>The problem is that <code>require.resolve</code> will return the module id (number) instead of a path and of course doing a readFile operation on a number is going to fail.</p>

<p>How do I make it compatible with both node and Webpack.</p>