Webpack plugin: how can I modify and re-parse a module after compilation? : <p>I'm working on a webpack plugin and can't figure out how to modify a module during the build. What I'm trying to do:</p>

<ul>
<li>Collect data via a custom loader (fine)</li>
<li>After all modules have been loaded, collect data gathered by my loader (fine)</li>
<li>Insert code I generate into an existing module in the build (doing this as described below, not sure if it's the best way)</li>
<li>'update' that module so that the code I added gets parsed and has its 'require's turned into webpack require calls (can't figure out how to do this correctly)</li>
</ul>

<p>Currently I'm hooking into 'this-compilation' on the compiler, then 'additional-chunk-assets' on the compilation. Grabbing the first chunk (the only one, currently, as I'm still in development), iterating through the modules in that chunk to find the one I want to modify. Then:</p>

<ul>
<li>Appending my generated source to the module's _cachedSource.source._source._value (I also tried appending to the module's ._source._value)</li>
<li>setting the ._cachedSource.hash to an empty string (as this seems to be necessary for the next step to work)</li>
<li>I pass the module to .rebuildModule() </li>
</ul>

<p>It looks like rebuildModule should re-parse the source, re-establish dependencies, etc. etc., but it's not parsing my require statements and changing them to webpack requires. The built file includes my modified source but the require('...') statements are unmodified.</p>

<p>How can I make the module I modified 'update' so that webpack will treat my added source the same as the originally parsed source? Is there something I need to do in addition to rebuildModule()? Am I doing this work too late in the build process? Or am I going about it the wrong way?</p>
