-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
chore: convert dev server to webpack plugin #3850
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
base: master
Are you sure you want to change the base?
Changes from all commits
5f340d6
8265a61
bd23953
50748da
323f9f9
cf33c23
c3cd6b7
9d35ac4
dc9075c
11be35c
85d443a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ if (!process.env.WEBPACK_SERVE) { | |
process.env.WEBPACK_SERVE = true; | ||
} | ||
|
||
const pluginName = "webpack-dev-server"; | ||
|
||
class Server { | ||
constructor(options = {}, compiler) { | ||
// TODO: remove this after plugin support is published | ||
|
@@ -35,7 +37,10 @@ class Server { | |
// Keep track of websocket proxies for external websocket upgrade. | ||
this.webSocketProxies = []; | ||
this.sockets = []; | ||
this.compiler = compiler; | ||
|
||
if (compiler) { | ||
this.compiler = compiler; | ||
} | ||
} | ||
|
||
static get DEFAULT_STATS() { | ||
|
@@ -126,6 +131,20 @@ class Server { | |
return path.resolve(dir, "node_modules/.cache/webpack-dev-server"); | ||
} | ||
|
||
apply(compiler) { | ||
this.compiler = compiler; | ||
|
||
let started = false; | ||
|
||
compiler.hooks.watchRun.tapPromise(pluginName, async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should enable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, plugin should work only for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping @alexander-akait There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, in my roadmap on the next week |
||
if (!started) { | ||
await this.start(); | ||
|
||
started = true; | ||
} | ||
}); | ||
} | ||
|
||
addAdditionalEntries(compiler) { | ||
const additionalEntries = []; | ||
|
||
|
@@ -395,7 +414,7 @@ class Server { | |
const { options } = this; | ||
|
||
if (!this.logger) { | ||
this.logger = this.compiler.getInfrastructureLogger("webpack-dev-server"); | ||
this.logger = this.compiler.getInfrastructureLogger(pluginName); | ||
} | ||
|
||
const compilerOptions = this.getCompilerOptions(); | ||
|
@@ -688,7 +707,7 @@ class Server { | |
if (typeof options.ipc === "boolean") { | ||
const isWindows = process.platform === "win32"; | ||
const pipePrefix = isWindows ? "\\\\.\\pipe\\" : os.tmpdir(); | ||
const pipeName = "webpack-dev-server.sock"; | ||
const pipeName = `${pluginName}.sock`; | ||
|
||
options.ipc = path.join(pipePrefix, pipeName); | ||
} | ||
|
@@ -1150,12 +1169,12 @@ class Server { | |
} | ||
|
||
setupHooks() { | ||
this.compiler.hooks.invalid.tap("webpack-dev-server", () => { | ||
this.compiler.hooks.invalid.tap(pluginName, () => { | ||
if (this.webSocketServer) { | ||
this.sendMessage(this.webSocketServer.clients, "invalid"); | ||
} | ||
}); | ||
this.compiler.hooks.done.tap("webpack-dev-server", (stats) => { | ||
this.compiler.hooks.done.tap(pluginName, (stats) => { | ||
if (this.webSocketServer) { | ||
this.sendStats(this.webSocketServer.clients, this.getStats(stats)); | ||
} | ||
|
@@ -2138,7 +2157,7 @@ class Server { | |
} | ||
} | ||
|
||
startCallback(callback) { | ||
startCallback(callback = () => {}) { | ||
this.start().then(() => callback(null), callback); | ||
} | ||
|
||
|
@@ -2210,7 +2229,7 @@ class Server { | |
"DEP_WEBPACK_DEV_SERVER_LISTEN" | ||
)(); | ||
|
||
this.logger = this.compiler.getInfrastructureLogger("webpack-dev-server"); | ||
this.logger = this.compiler.getInfrastructureLogger(pluginName); | ||
|
||
if (typeof port === "function") { | ||
fn = port; | ||
|
Uh oh!
There was an error while loading. Please reload this page.