1 thought on “NormalModuleReplacementPlugin doesn’t handle requires in newResource

  1. @sokra, how do you feel about adding this to the standard plugin library? It sounds like something a lot of people are after.

    // Adapted from https://github.com/peerigon/alamid/blob/master/lib/core/bundle/AlamidWebpackPlugin.class.js
    
    var FileNameReplacementPlugin = function (toFind, replaceWith) {
      toFind      = toFind      || ".server.";
      replaceWith = replaceWith || ".client.";
    
      return {
          "apply":  function (compiler) {
                      compiler.plugin(
                        "normal-module-factory",
    
                        function (normalModuleFactory) {
                          normalModuleFactory.plugin(
                            "after-resolve",
    
                            function (result, callback) {
                              [
                                "request",
                                "userRequest",
                                "resource"
    
                              ].forEach(
                                function (key) {
                                  result[key] = result[key].replace(toFind, replaceWith);
                                }
                              );
    
                              return callback(null, result);
                            }
                          );
                        }
                      );
                    }
      };
    };
    
    module.exports = FileNameReplacementPlugin;
    

Comments are closed.