Skip to content

Commit

Permalink
fix: options has an unknown property 'before' (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
milosivanovic committed Feb 12, 2022
1 parent fe2cd08 commit 28de3ed
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@ class ErrorOverlayPlugin {
const devServerEnabled = !!compiler.options.devServer
const sockOptions = {}
if (devServerEnabled) {
sockOptions.sockHost = compiler.options.devServer.sockHost
sockOptions.sockPath = compiler.options.devServer.sockPath
sockOptions.sockPort = compiler.options.devServer.sockPort
// In the webpack config it's possible to override the websocket server's
// connect URL for clients that need to connect through a proxy or other means.
//
// Use a webSocketURL config if present, otherwise default to the same address
// as the devServer:
sockOptions.sockHost =
compiler.options.devServer.client?.webSocketURL?.hostname ||
compiler.options.devServer.host
sockOptions.sockPath =
compiler.options.devServer.client?.webSocketURL?.pathname ||
compiler.options.devServer.webSocketServer?.options.path ||
'/ws'
sockOptions.sockPort =
compiler.options.devServer.client?.webSocketURL?.port ||
compiler.options.devServer.port
}

compiler.hooks.entryOption.tap(className, (context, entry) => {
Expand All @@ -23,12 +35,13 @@ class ErrorOverlayPlugin {

compiler.hooks.afterResolvers.tap(className, ({ options }) => {
if (devServerEnabled) {
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) => {
if (originalOnBeforeSetupMiddleware) {
originalOnBeforeSetupMiddleware(devServer)
}
app.use(errorOverlayMiddleware())
devServer.app.use(errorOverlayMiddleware())
}
}
})
Expand Down

0 comments on commit 28de3ed

Please sign in to comment.