<h1 dir="auto">Bug report</h1>




<p dir="auto"><strong>What is the current behavior?</strong><br>
i want modify vue source in webpack</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const Dependency = require('webpack/lib/Dependency');

class MyDependency extends Dependency {
  // Use the constructor to save any information you need for later
  constructor(module) {
    super();
    this.module = module;
  }
}

MyDependency.Template = class MyDependencyTemplate {
  apply(dep, source) {
    // dep is the MyDependency instance, so the module is dep.module
    source.replace(0, source.source().length - 1, source.source() )
  }
};

module.exports = class MyPlugin {
  apply(compiler) {
    compiler.hooks.compilation.tap('MyPluginName', compilation =&gt; {
      compilation.dependencyTemplates.set(
        MyDependency,
        new MyDependency.Template()
      );
      compilation.hooks.buildModule.tap('MyPluginName', module =&gt; {
        module.addDependency(new MyDependency(module));
      });
    });
  }
};"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-v">Dependency</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'webpack/lib/Dependency'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-k">class</span> <span class="pl-v">MyDependency</span> <span class="pl-k">extends</span> <span class="pl-v">Dependency</span> <span class="pl-kos">{</span>
  <span class="pl-c">// Use the constructor to save any information you need for later</span>
  <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-s1">module</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">super</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">module</span> <span class="pl-c1">=</span> <span class="pl-s1">module</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-v">MyDependency</span><span class="pl-kos">.</span><span class="pl-c1">Template</span> <span class="pl-c1">=</span> <span class="pl-k">class</span> <span class="pl-v">MyDependencyTemplate</span> <span class="pl-kos">{</span>
  <span class="pl-en">apply</span><span class="pl-kos">(</span><span class="pl-s1">dep</span><span class="pl-kos">,</span> <span class="pl-s1">source</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-c">// dep is the MyDependency instance, so the module is dep.module</span>
    <span class="pl-s1">source</span><span class="pl-kos">.</span><span class="pl-en">replace</span><span class="pl-kos">(</span><span class="pl-c1">0</span><span class="pl-kos">,</span> <span class="pl-s1">source</span><span class="pl-kos">.</span><span class="pl-en">source</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">length</span> <span class="pl-c1">-</span> <span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-s1">source</span><span class="pl-kos">.</span><span class="pl-en">source</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">)</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span>

<span class="pl-smi">module</span><span class="pl-kos">.</span><span class="pl-c1">exports</span> <span class="pl-c1">=</span> <span class="pl-k">class</span> <span class="pl-v">MyPlugin</span> <span class="pl-kos">{</span>
  <span class="pl-en">apply</span><span class="pl-kos">(</span><span class="pl-s1">compiler</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-s1">compiler</span><span class="pl-kos">.</span><span class="pl-c1">hooks</span><span class="pl-kos">.</span><span class="pl-c1">compilation</span><span class="pl-kos">.</span><span class="pl-en">tap</span><span class="pl-kos">(</span><span class="pl-s">'MyPluginName'</span><span class="pl-kos">,</span> <span class="pl-s1">compilation</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
      <span class="pl-s1">compilation</span><span class="pl-kos">.</span><span class="pl-c1">dependencyTemplates</span><span class="pl-kos">.</span><span class="pl-en">set</span><span class="pl-kos">(</span>
        <span class="pl-v">MyDependency</span><span class="pl-kos">,</span>
        <span class="pl-k">new</span> <span class="pl-v">MyDependency</span><span class="pl-kos">.</span><span class="pl-c1">Template</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
      <span class="pl-kos">)</span><span class="pl-kos">;</span>
      <span class="pl-s1">compilation</span><span class="pl-kos">.</span><span class="pl-c1">hooks</span><span class="pl-kos">.</span><span class="pl-c1">buildModule</span><span class="pl-kos">.</span><span class="pl-en">tap</span><span class="pl-kos">(</span><span class="pl-s">'MyPluginName'</span><span class="pl-kos">,</span> <span class="pl-smi">module</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-smi">module</span><span class="pl-kos">.</span><span class="pl-en">addDependency</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-v">MyDependency</span><span class="pl-kos">(</span><span class="pl-smi">module</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
      <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>






<p dir="auto"><strong>What is the expected behavior?</strong><br>
I can replace all code in Source<br>
because Code I need to convert Babel conversion</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  4.46.4<br>
Node.js version: v16.5.0<br>
Operating System: mac<br>
Additional tools: vscode</p>
<h2 dir="auto">Feature request</h2>





<p dir="auto"><strong>What is the expected behavior?</strong><br>
Be able to intercept async load failures and retry by recreating the script tag with cache busted url</p>
<p dir="auto"><strong>What is motivation or use case for adding/changing the behavior?</strong><br>
We found that retrying the download with the use of cache busting params is very effective, and we could not find a way to utilize it correctly. existing plugins replace the jsonp loading code which is not possible with version 5, causing the need to duplicate the logic and patch it to use the duplicated code instead of the original</p>
<p dir="auto"><strong>How should this be implemented in your opinion?</strong><br>
Either expose a way to be able to add search params for the purpose of cache busing in user land. or add a hook to augment the <code class="notranslate">loadingEnded</code> function in jsonp runtime</p>
<p dir="auto"><strong>Are you willing to work on this yourself?</strong><br>
yes, with guidance from a contributer</p>