-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
devServer v4: options has an unknown property 'before' #88
Conversation
066980f
to
83d418e
Compare
83d418e
to
8c95ee4
Compare
src/index.js
Outdated
sockOptions.sockHost = compiler.options.devServer.client && | ||
compiler.options.devServer.client.webSocketURL && | ||
compiler.options.devServer.client.webSocketURL.hostname || compiler.options.devServer.host | ||
sockOptions.sockPath = ( | ||
compiler.options.devServer.client && | ||
compiler.options.devServer.client.webSocketURL && | ||
compiler.options.devServer.client.webSocketURL.pathname | ||
) | ||
|| | ||
( | ||
compiler.options.devServer.webSocketServer && | ||
compiler.options.devServer.webSocketServer.options && | ||
compiler.options.devServer.webSocketServer.options.path | ||
) | ||
|| '/ws' | ||
sockOptions.sockPort = compiler.options.devServer.client && | ||
compiler.options.devServer.client.webSocketURL && | ||
compiler.options.devServer.client.webSocketURL.port || compiler.options.devServer.port |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like yarn format
needs to be run on this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good!
src/index.js
Outdated
sockOptions.sockHost = compiler.options.devServer.client && | ||
compiler.options.devServer.client.webSocketURL && | ||
compiler.options.devServer.client.webSocketURL.hostname || compiler.options.devServer.host |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use compiler.options.devServer.client?.webSocketURL?.hostname
here? Would be more readable if so.
Also, I suggest adding a comment per the description about why this is necessary re: "TWO types of configurations both specified in the webpack config: the server config, and the client config, etc."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work chipping away at this @milosivanovic I left a couple comments that aren't critical to address.
I tried this on an SPA test project using:
webpack 5.57.1
webpack-cli 4.8.0
webpack-dev-server 4.3.1
Dev server ran successfully and is displaying error overlay. However, I'm seeing the same console error along with several others:
These errors are only present when the ErrorOverlayPlugin
is used. I did some digging but was unable to diagnose.
The "unexpected token" errors is particularly confusing. Failing the app's index.html... 🤔
Wish I could be of more help but I do hope this adds some positive momentum.
@thedavidprice Thanks for your review! I hope I addressed those comments in my latest commit. The 404 error is strange, and yes, it does only show when the plugin is used. I can say that the functionality works despite the 404, which puts the plugin in a better place than it is on the main branch (not working at all.) We could either try to resolve that in this PR, or commit a subsequent PR after the issue is identified. I'll leave that up for the maintainer to decide. @gregberge When you have time to check this out, let us know what you think. |
Changes look good! I think we need to resolve the 404. But that's up to @gregberge |
@gregberge Thanks |
any updates? we're waiting on this fix otherwise this package is unusable for us |
Guys can we please get this merged? @thedavidprice @milosivanovic |
Sorry all, I've no permissions for this repo. And we've now removed the package from RedwoodJS due to the incompatibility so I can't take on responsibility here. Nudging @gregberge |
const originalBefore = options.devServer.before | ||
options.devServer.before = (app, server) => { | ||
if (originalBefore) { | ||
originalBefore(app, server, compiler) | ||
const originalOnBeforeSetupMiddleware = | ||
options.devServer.onBeforeSetupMiddleware | ||
options.devServer.onBeforeSetupMiddleware = (devServer) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This broke compatibility with webpack-dev-server v3.
Fixes #83
As per https://github.com/webpack/webpack-dev-server/blob/master/migration-v4.md#-breaking-changes, the locations of the websocket parameters for
host
,port
andpath
have moved. It's important to note that there are TWO types of configurations both specified in the webpack config: the server config, and the client config.The server config tells webpack-dev-server where to listen, and the client config tells the client how to connect to webpack-dev-server. Under normal circumstances these wouldn't differ, but in the event a proxy is required/preferred for a particular development environment, then the client might need to connect to a different
host
/port
/path
in order to reach the server.These differences are respected in this PR:
path
set to/ws
as I'm not sure how to get this default value programmatically from the webpack server config -- the default in the webpacker config is/ws
.)host
,port
orpath
, then use those values instead.Tested and working with the following versions:
I am seeing this 404 in the developer console though (in my case I'm running webpack-dev-server on port 8081):

I'm not sure what that's referring to or why it's trying to use
sockjs
when there is already an established websocket at/ws
.