title: webpack plugin to replace a function with another
body: <p>I am trying to create a webpack plugin, that will parse the code for a certain function and replace it with another function, that plugin will also expose the new function as a global.</p>
  
  <pre><code>class someName {
    constructor(local, domain, translationFile, options) {
    }
  
    apply(compiler) {
  
      // exposing ngt function as a global
      compiler.plugin('make', function(compilation, callback) {
        var childCompiler = compilation.createChildCompiler('someNameExpose');
        childCompiler.apply(new webpack.DefinePlugin({
          ngt: function(singular , plural, quantity) {
            return quantity == 1 ? singular : plural;
          }
        }));
        childCompiler.runAsChild(callback);
      });
  
      // searching for the getValue function
      compiler.parser.plugin(`call getValue`, function someNameHandler(expr) {
  
        // create a function to replace getValue with
        let results = 'ngt('+ expr.arguments  +')';
        const dep = new ConstDependency(results, expr.range);
        dep.loc = expr.loc;
        this.state.current.addDependency(dep);
        return true;
      });
    }
  }
  
  module.exports = someName;
  </code></pre>
  
  <p><strong>update / rephrase</strong></p>
  
  <p>I have an issue here, when <code>compiler.parser.plugin('call getValue', function someNameHandler(expr) {...}</code> block is commented the <code>ngt</code> function exist as a global.</p>
  
  <p>when its not commented, i get an error, ngt is undefined.</p>
  
  <p>commented i mean <code>/**/</code></p>
  
  <p>I found a workaround for that but its far then idea. right now what I do is I export an anonymous function that does what i want.</p>
  
  <p>You can see the plugin here:
  <a href="https://github.com/yanivkalfa/i18n-gettext-webpack-plugin/blob/master/src/index.js" rel="noreferrer">Github</a></p>