Multicompiler with multiple output paths breaks WDS

I’m submitting a feature request

Webpack version:
2.x

Please tell us about your environment:
OSX 10.x

Current behavior:
Currently, a Multicompiler instance with a different output.path specified for each config will boil the outputPath property down to a “common” path. I’m referring to this block of code

Object.defineProperty(this, “outputPath”, {
configurable: false,
get: function() {
var commonPath = compilers[0].outputPath;
for(var i = 1; i < compilers.length; i++) {
while(compilers[i].outputPath.indexOf(commonPath) !== 0 && /[\/\\]/.test(commonPath)) {
commonPath = commonPath.replace(/[\/\\][^\/\\]*$/, “”);
}
}
if(!commonPath && compilers[0].outputPath[0] === “/”) return “/”;
return commonPath;
}
});

. This breaks WDS filename resolution.

Expected/desired behavior:
WDS should serve resources from both paths or at least offer the ability to choose the first/preferred output.path when constructing the filename. I need to be able to output my files to separate (not necessarily nested) directories without breaking resolution.

  • What is the motivation / use case for changing the behavior?
    In my setup, I am trying to build two separate apps in parallel and I need to be able to share resources between the two, including async modules. Consider the following config:
module.exports = [
  {
    context: __dirname,
    entry: "./app.js",
    output: {
      filename: "app.js",
      path: path.resolve(__dirname, './app/dist'),
      publicPath: '/static/javascript/dist/'
    },
    ...
  },
  {
    context: __dirname,
    entry: "./widget.js",
    output: {
      filename: "widget.js",
      path: path.resolve(__dirname, './widget/dist'),
      publicPath: '/widget/dist/'
    },
    ...
  }
]

Author: Fantashit

1 thought on “Multicompiler with multiple output paths breaks WDS

Comments are closed.