webpack-dev-server: Multicompiler with multiple output paths breaks WDS
Moved from https://github.com/webpack/webpack/issues/3091 - by @drphelps:
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 https://github.com/webpack/webpack/blob/547295ca0e91dd5bb2c446e2df19c887c6aa053c/lib/MultiCompiler.js#L51-L63. 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/'
},
...
}
]
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 26
- Comments: 20 (4 by maintainers)
Commits related to this issue
- added support for multi-compiler configuration see: https://github.com/webpack/webpack-dev-server/issues/641 — committed to iMoses/webpack-dev-middleware by iMoses 8 years ago
- added support for multi-compiler configuration see: https://github.com/webpack/webpack-dev-server/issues/641 — committed to iMoses/webpack-dev-middleware by iMoses 8 years ago
- resolve merge conflict for PR #151 (#187) * added support for multi-compiler configuration see: https://github.com/webpack/webpack-dev-server/issues/641 * fixed compiler reference in the multi-c... — committed to webpack/webpack-dev-middleware by faceyspacey 7 years ago
Any update on this?
part of the code:
server.js
webpack.dev.js
My solution to a similar problem with
webpack multi compiller&react&HMRI have 2 sub projects: app & widget
App located at
localhost:8080/*(exceptlocalhost:8080/widget) Widget located atlocalhost:8080/widgetwebpack.config.js
dev-server.js
And… add
react-hot-loaderin app & widget entrypointsWorks great 👍
If you want to have the same
output.publicPathfor multiple configs, or have them nested so one is the root and the other is a sub-path, then you need to make sure the configs have the exact same setting foroutput.pathotherwise only the first config will have effect. Not sure why this is, I spent several hours trial and error to find this out so I just wanted to mention it for future reference.UPDATE: Seems like this only works if you have the exact same publicPath. Nesting them, for example having one config with
output.publicPath = "/"and one withoutput.publicPath = "/sub"does not work.UPDATE2: Seems like the trick is to set
output.pathto exactly followoutput.publicPath. For example the following will work for nested paths:Instead of constantly asking for updates, you can help. PR https://github.com/webpack/webpack-dev-middleware/pull/151 is a good starting point, but was never finished.
This would be very nice to have!
We are trying to fit webpack into an existing toolchain, requiring multiple configurations. The real killer would be to have a webpack-dev-server serving the assets from both the configs, at the paths specified by each.
This bug blocks me to use the WDS, but I found a solution from https://github.com/glenjamin/webpack-hot-middleware, the
webpack-hot-middlewareallows me to use multi compiler instances.@SpaceK33z I pushed a quick fix which does the trick for me. Let me know what you think.
#187 resolved the root issue that @SpaceK33z moved over from webpack. If there are errors being thrown please do report it as a bug separately and we can triage. If there’s only difficulty in getting it to work, please head to StackOverflow or the webpack gitter for more discussion and peer troubleshooting.
Hi, was there any progress on this? I see that webpack/webpack-dev-middleware#187 fixed this problem in the middleware part, so that’s not a problem anymore, and the code actually looks like it’s supposed to be able to run multi-compiler configurations – anyone knows what may cause this not to work (as it looks like it should)?